@PrimaryKeyJoinColumn(...) is not working equivalently to @JoinColumn(..., insertable =
false, updatable = false)
-----------------------------------------------------------------------------------------------------------------
Key: HHH-5741
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5741
Project: Hibernate Core
Issue Type: Bug
Components: annotations, core, entity-manager, metamodel
Affects Versions: 3.6.0
Environment: Hibernate Core 3.6, HSQLDB, JavaSE, Ant
Reporter: Karsten Wutzke
Priority: Critical
When annotating classes with @JoinColumn(..., insertable = false, updatable = false)
validation is working as expected:
@ManyToOne
@JoinColumns(value = {@JoinColumn(name = "country_code", referencedColumnName =
"country_code", insertable = false, updatable = false), @JoinColumn(name =
"state_code", referencedColumnName = "state_code", insertable = false,
updatable = false), @JoinColumn(name = "city_name", referencedColumnName =
"name", insertable = false, updatable = false)})
private City city = null;
When annotating with the equivalent @PrimaryKeyJoinColumn, e.g.:
@ManyToOne
@PrimaryKeyJoinColumns(value = {@PrimaryKeyJoinColumn(name = "country_code",
referencedColumnName = "country_code"), @PrimaryKeyJoinColumn(name =
"state_code", referencedColumnName = "state_code"),
@PrimaryKeyJoinColumn(name = "city_name", referencedColumnName =
"name")})
private City city = null;
... validation fails.
As every child knows (*cough*) @PrimaryKeyJoinColumn(...) is equivalent to
@JoinColumn(..., insertable = false, updatable = false). See here:
http://stackoverflow.com/questions/4205628/jpa-is-primarykeyjoincolumn-th...
Stack trace:
Exception in thread "main" javax.persistence.PersistenceException:
[PersistenceUnit: geoinfo] Unable to build EntityManagerFactory
at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:911)
at
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at tld.geoinfo.Main.main(Main.java:27)
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity:
tld.geoinfo.model.ZipArea column: city_name (should be mapped with
insert="false" update="false")
at
org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:675)
at
org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:697)
at
org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:719)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:473)
at org.hibernate.mapping.RootClass.validate(RootClass.java:235)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1332)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1835)
at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902)
... 4 more
Obviously, @PrimaryKeyJoinColumn is treated to be writable, which is wrong.
I have attached two SSCCE programs using JavaSE, HSQLDB, and Ant. The one uses @JoinColumn
and works, whereas the other uses @PrimaryKeyJoinColumn and doesn't work. Just enter
"ant run" in a shell.
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira