Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » eclispselink doesn't generate primary key constraint [@ElementCollection] (Using @ElementCollection eclipselink generates table without primary key)
eclispselink doesn't generate primary key constraint [@ElementCollection] [message #557312] Mon, 06 September 2010 16:04 Go to next message
Gilberto Caetano de Andrade is currently offline Gilberto Caetano de Andrade
Messages: 44
Registered: July 2009
Member
OpenSuse 11.3
java version "1.6.0_20"
eclipselink 2.1.1


Hi,


I'm using @ElementCollection annotation to persist some strings list:

    @ElementCollection
    @CollectionTable(
             name="shiro_role_permission",
             joinColumns=@JoinColumn(name="ROLE_ID",referencedColumnName="ID"))
    @Column(name="permission")
    private Set<String> permissions;



Executing my tests I'm getting this exception with DBunit:
Testcase: org.apache.click.extras.security.shiro.UserJpaTest:        Caused an ERROR
SHIRO_ROLE_PERMISSION
org.dbunit.dataset.NoPrimaryKeyException: SHIRO_ROLE_PERMISSION  at org.dbunit.operation.DeleteOperation.getOperationData(DeleteOperation.java:81)  at org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:170)  at org.apache.click.extras.security.shiro.UserJpaTest.closeEntityManager(UserJpaTest.java:69)  at org.dbunit.operation.DeleteOperation.getOperationData(DeleteOperation.java:81)



Activating the eclipselink log I've found that the TABLE has not primary key:
[EL Config]: 2010-09-06 13:01:32.01--ServerSession(22730182)--Connection(13948523)--Thread(Thread[main,5,main])--Connected: jdbc:h2:mem
	User: CLICK
	Database: H2  Version: 1.2.131 (2010-03-05)
	Driver: H2 JDBC Driver  Version: 1.2.131 (2010-03-05)
[EL Info]: 2010-09-06 13:01:32.482--ServerSession(22730182)--Thread(Thread[main,5,main])--file:/home/gilberto/dev/netbeans-config/coi/orm/target/test-classes/_click login successful
[EL Fine]: 2010-09-06 13:01:32.541--ServerSession(22730182)--Connection(13599389)--Thread(Thread[main,5,main])--CREATE TABLE shiro_user_role (user_id BIGINT NOT NULL, role_id BIGINT NOT NULL, PRIMARY KEY (user_id, role_id))
[EL Fine]: 2010-09-06 13:01:32.605--ServerSession(22730182)--Connection(13599389)--Thread(Thread[main,5,main])--CREATE TABLE shiro_role_permission (ROLE_ID BIGINT NOT NULL, permission VARCHAR)
[EL Fine]: 2010-09-06 13:01:32.608--ServerSession(22730182)--Connection(13599389)--Thread(Thread[main,5,main])--CREATE TABLE shiro_role (ID BIGINT NOT NULL, DESCRIPTION VARCHAR(255), NAME VARCHAR(50) NOT NULL, PRIMARY KEY (ID))



Is it the default behavior? Can I change it?

Regards,

Gilberto

[Updated on: Mon, 06 September 2010 16:05]

Report message to a moderator

Re: eclispselink doesn't generate primary key constraint [@ElementCollection] [message #557471 is a reply to message #557312] Tue, 07 September 2010 14:40 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I assume the primary key constraint is not defined because ElementCollection supports duplicate values by default, so a primary key constraint would prevent this.

But there should be someway to have the constraint auto generated, at least if Set or a unique constraint is defined. Perhaps an annotation option to not support duplicates. Please log a bug and vote for it. Also mention that if an indexed List, or Map key is used the constraint should always be generated on the index and foreign key.

As a workaround you can create/alter the table using your own DDL scripts, or using a SessionCustomizer in EclipseLink and altering the table through the Session (you will need to login, then execute the alter SQL).


James : Wiki : Book : Blog : Twitter
Previous Topic:Exception during meta-model generation in maven
Next Topic:How can you enable delimited-identifiers programatically?
Goto Forum:
  


Current Time: Fri Oct 31 09:31:51 GMT 2014

Powered by FUDForum. Page generated in 0.05734 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software