Duplicate column with TABLE_PER_CLASS and @OrderColumn,, bug or incorrect mapping? [message #873674] |
Fri, 18 May 2012 20:18 |
Shahim Essaid Messages: 40 Registered: July 2009 |
Member |
|
|
Hi all,
I am using Texo to generate JPA entities. When I set the inheritance to table per class, the DDL that is generated by EclipseLink is not correct. A simplified version of the entities that show the problem are below. The incorrect generated DDL is:
CREATE TABLE BaseToken_lemmaEntries (EMBUCT_BASETOKEN_DBID INTEGER NOT NULL, lemmaEntries_DBID INTEGER NOT NULL, lemmaEntries_ORDER INTEGER, EMBUCT_SYMBOLTOKEN_DBID INTEGER NOT NULL, lemmaEntries_ORDER INTEGER, EMBUCT_WORDTOKEN_DBID INTEGER NOT NULL, lemmaEntries_ORDER INTEGER,
PRIMARY KEY (EMBUCT_BASETOKEN_DBID, lemmaEntries_DBID, EMBUCT_SYMBOLTOKEN_DBID, EMBUCT_WORDTOKEN_DBID))
Notice the duplicate order columns and the incorrect PK. The problem appears to be that the "token" entities are not saved into their own tables, instead they are all mapped to a single table even with a table per class inheritance.
The original entity hierarchy is much larger and there are more "token" entities. Each of the "token" entities is mapped to the same table above and the PK is larger. The code below should reproduce the problem. I tried this with the current release and the current 2.4 stable build.
Thanks,
Shahim
package db.uima.cas;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import static javax.persistence.InheritanceType.TABLE_PER_CLASS;
import javax.persistence.GeneratedValue;
@Entity(name = "UC_TOP")
@Inheritance(strategy = TABLE_PER_CLASS)
public class TOP {
@Id
@GeneratedValue
int dbid;
}
package db.edu.mayo.bmi.uima.core.type;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderColumn;
import db.uima.cas.TOP;
@Entity(name = "EMBUCT_BASETOKEN")
public class BaseToken extends TOP {
@Basic(optional = true)
private int tokenNumber = 0;
@Basic(optional = true)
private String normalizedForm = null;
@Basic(optional = true)
private String partOfSpeech = null;
@ManyToMany(cascade = { CascadeType.MERGE, CascadeType.PERSIST,
CascadeType.REFRESH }, targetEntity = TOP.class)
@OrderColumn()
@JoinTable(name = "BaseToken_lemmaEntries")
private List<TOP> lemmaEntries = new ArrayList<TOP>();
}
package db.edu.mayo.bmi.uima.core.type;
import javax.persistence.Entity;
@Entity(name = "EMBUCT_SYMBOLTOKEN")
public class SymbolToken extends BaseToken {
}
package db.edu.mayo.bmi.uima.core.type;
import javax.persistence.Basic;
import javax.persistence.Entity;
@Entity(name = "EMBUCT_WORDTOKEN")
public class WordToken extends BaseToken {
@Basic(optional = true)
private int capitalization = 0;
@Basic(optional = true)
private int numPosition = 0;
@Basic(optional = true)
private String suggestion = null;
@Basic(optional = true)
private String canonicalForm = null;
}
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="uima.db"
transaction-type="RESOURCE_LOCAL">
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/uima"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="pass"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="eclipselink.logging.level" value="INFO"/>
<property name="eclipselink.jpa.uppercase-column-names" value="true"/>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
</properties>
</persistence-unit>
</persistence>
[Updated on: Fri, 18 May 2012 20:21] Report message to a moderator
|
|
|
|
|
|
Re: Duplicate column with TABLE_PER_CLASS and @OrderColumn,, bug or incorrect mapping? [message #876110 is a reply to message #875900] |
Wed, 23 May 2012 23:27 |
Shahim Essaid Messages: 40 Registered: July 2009 |
Member |
|
|
James Sutherland wrote on Wed, 23 May 2012 10:11Seems to be a bug in TABLE_PER_CLASS inheritance with join tables and DDL. Please log a bug.
You may try using another inheritance type, or a mapped superclass, or using your own DDL scripts.
I did not check the JPA spec but it appears that EclipseLink is behaving as if the @JoinTable is an inherited annotation. Is it? If it is, it should probably be ignored in the table per class inheritance mappings of the sub entities.
The problem is that there is an @JoinTable on a super entity and the sub entities are not annotated with association overrides as noted by Martin. This is causing EclipseLink to map all the sub entity joins to the same join table as separate columns.
For now I am using a script to strip all the @JoinTable annotations from the Texo generated code since they are not really needed.
Bug report created:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=380485
Best,
Shahim
[Updated on: Wed, 23 May 2012 23:46] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03338 seconds