Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Duplicate column with TABLE_PER_CLASS and @OrderColumn,, bug or incorrect mapping?
Duplicate column with TABLE_PER_CLASS and @OrderColumn,, bug or incorrect mapping? [message #873674] Fri, 18 May 2012 16:18 Go to next message
Shahim Essaid is currently offline 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 16:21]

Report message to a moderator

Re: Duplicate column with TABLE_PER_CLASS and @OrderColumn,, bug or incorrect mapping? [message #873708 is a reply to message #873674] Fri, 18 May 2012 18:30 Go to previous messageGo to next message
Shahim Essaid is currently offline Shahim Essaid
Messages: 40
Registered: July 2009
Member
A follow up. The @JoinTable on BaseToken appears to be the problem. This annotation is added by Texo even though it is not appropriate in this case. Should EclipseLink be able to handle this situation in a better way?
Re: Duplicate column with TABLE_PER_CLASS and @OrderColumn,, bug or incorrect mapping? [message #873860 is a reply to message #873708] Sat, 19 May 2012 05:12 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5329
Registered: July 2009
Senior Member
My guess is that to solve this an association override has to be added to each subclass...

Other solution, question: does it work fine if you keep the JoinTable annotation but without the name?

gr. Martin

On 05/19/2012 12:30 AM, Shahim Essaid wrote:
> A follow up. The @JoinTable on BaseToken appears to be the problem. This annotation is added by Texo even though it is
> not appropriate in this case. Should EclipseLink be able to handle this situation in a better way?


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: Duplicate column with TABLE_PER_CLASS and @OrderColumn,, bug or incorrect mapping? [message #875900 is a reply to message #873860] Wed, 23 May 2012 10:11 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Seems 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.


James : Wiki : Book : Blog : Twitter
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 19:27 Go to previous message
Shahim Essaid is currently offline Shahim Essaid
Messages: 40
Registered: July 2009
Member
James Sutherland wrote on Wed, 23 May 2012 10:11
Seems 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 19:46]

Report message to a moderator

Previous Topic:Force index in MySQL 5.1
Next Topic:Toplink to EclipseLink Migration
Goto Forum:
  


Current Time: Wed Aug 27 21:22:26 EDT 2014

Powered by FUDForum. Page generated in 0.01899 seconds