[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5764) AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId
Karsten Wutzke (JIRA)
noreply at atlassian.com
Tue Nov 30 14:01:14 EST 2010
AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId
---------------------------------------------------------------------------------------------
Key: HHH-5764
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5764
Project: Hibernate Core
Issue Type: Bug
Components: annotations, core, metamodel
Affects Versions: 3.6.0
Environment: Hibernate 3.6, JavaSE, HSQLDB, Ant (see SSCCE attached)
Reporter: Karsten Wutzke
Priority: Critical
Attachments: transmuc-hib-embeddedid-transitive-comp-pk-broken.zip
I have three tables:
CREATE TABLE PostAddresses
(
contact_id INTEGER NOT NULL,
ordinal_nbr SMALLINT NOT NULL,
PRIMARY KEY (contact_id, ordinal_nbr)
);
CREATE TABLE Foos
(
contact_id INTEGER NOT NULL,
ordinal_nbr SMALLINT NOT NULL,
PRIMARY KEY (contact_id, ordinal_nbr),
FOREIGN KEY (contact_id, ordinal_nbr) REFERENCES PostAddresses
(contact_id, ordinal_nbr)
);
CREATE TABLE Bars
(
contact_id INTEGER NOT NULL,
ordinal_nbr SMALLINT NOT NULL,
numba INTEGER NOT NULL,
PRIMARY KEY (contact_id, ordinal_nbr, numba),
FOREIGN KEY (contact_id, ordinal_nbr) REFERENCES Foos (contact_id,
ordinal_nbr)
);
Simple logic: Bars -> Foos -> PostAddresses all by (contact_id, ordinal_nbr),
whatever it means.
Here the six entity and respective composite key classes.
@Entity
@Table(name = "PostAddresses")
public class PostAddress implements Serializable
{
@EmbeddedId
private PostAddressId embeddedId;
...
}
@Embeddable
public class PostAddressId implements Serializable
{
@Column(name = "contact_id")
private Integer contactId;
@Column(name = "ordinal_nbr")
private Integer ordinalNbr = 1;
...
}
@Entity
@Table(name = "Foos")
public class Foo implements Serializable
{
@EmbeddedId
private FooId embeddedId;
@MapsId(value = "postAddressId")
@OneToOne
@JoinColumns(value = {@JoinColumn(name = "contact_id",
referencedColumnName = "contact_id"), @JoinColumn(name = "ordinal_nbr",
referencedColumnName = "ordinal_nbr")})
private PostAddress postAddress = null;
...
}
@Embeddable
public class FooId implements Serializable
{
@Embedded
private PostAddressId postAddressId; //just one field!
...
}
@Entity
@Table(name = "Bars")
public class Bar implements Serializable
{
@EmbeddedId
private BarId embeddedId;
...
}
@Embeddable
public class BarId implements Serializable
{
@Embedded
private FooId fooId;
@Column(name = "numba")
private Integer numba;
...
}
It's really nothing special, Bar references Foo, Foo references PostAddress,
all via composite key class. Since the foreign keys are composite and part of
the PK, I must nest the ID classes into the ID classes. I thought this is
correct. However, I get the following stack trace with Hibernate 3.6:
org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: tld.transmuc.model.Foo
at org.hibernate.cfg.CopyIdentifierComponentSecondPass.doSecondPass(CopyIdentifierComponentSecondPass.java:101)
at org.hibernate.cfg.Configuration.processSecondPassesOfType(Configuration.java:1424)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1388)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1477)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1096)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:278)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:362)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at tld.transmuc.Main.main(Main.java:27)
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: transmuc] Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:374)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at tld.transmuc.Main.main(Main.java:27)
Caused by: org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: tld.transmuc.model.Foo
at org.hibernate.cfg.CopyIdentifierComponentSecondPass.doSecondPass(CopyIdentifierComponentSecondPass.java:101)
at org.hibernate.cfg.Configuration.processSecondPassesOfType(Configuration.java:1424)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1388)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1477)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1096)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:278)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:362)
... 4 more
Hibernate is telling me about a problem with the @MapsId annotation and the Foo class:
org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: tld.transmuc.model.Foo
It appears to be a bug. Even if I omit the @Embedded annotation from the ID classes, the exception is still there.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list