-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: primary key in CollectionOfElements
PostPosted: Tue Feb 07, 2006 11:06 am 
Beginner
Beginner

Joined: Fri Nov 21, 2003 4:50 am
Posts: 23
Hi,

is there a way to specify the primary key in a "CollectionOfElements" JoinTable?

The example output defines a primary key which is a show stopper (only 2 elements possible, boolean value is pk in a collection):

Code:
create table Parent_elements (Parent_id bigint not null, enabled bit not null, child_id bigint not null, primary key (Parent_id, enabled))



Example:
Code:
import org.hibernate.annotations.AccessType;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.util.Set;

public class TestPrimaryKeyForCollectionOfElements {

    @Entity
    @AccessType("field")
    @Table(name = "Child")
    static class Child {
        @Id
        Long id;

        String name;
    }


    @Entity
    @AccessType("field")
    @Table(name = "Parent")
    static class Parent {

        @Id
        Long id;

        @CollectionOfElements(targetElement = Element.class)
        Set<Element> elements;

    }

    @Embeddable
    static class Element {
        boolean enabled = true;

        @ManyToOne(optional = false)
        Child child;
    }


    public static void main(String[] pArgs) throws Exception {
        AnnotationConfiguration tConfiguration = new AnnotationConfiguration();
        tConfiguration.addAnnotatedClass(Child.class);
        tConfiguration.addAnnotatedClass(Element.class);
        tConfiguration.addAnnotatedClass(Parent.class);
        tConfiguration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");

        SchemaExport tSchemaExport = new SchemaExport(tConfiguration);

        tSchemaExport.create(true, false);
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 2:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
add @JoinTable(joinColumns=...)

Please confirm this is actually written in the documentation

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 7:12 am 
Beginner
Beginner

Joined: Fri Nov 21, 2003 4:50 am
Posts: 23
emmanuel wrote:
add @JoinTable(joinColumns=...)


where?

- on the collection, only the join to the parent is possible, the collection elements are embedded! It changes nothing,the default is ok

- on the ManyToOne from the collection element, changes only the join to the child table. The default is ok.

The problem is the primary key of the collection table, which breaks the collection sematics in this case!

emmanuel wrote:
Please confirm this is actually written in the documentation


Where? I've read the documention many times and cannot find it


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 10:03 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Oh i misread your question.
I think this is a bug, since we might add child_id in the PK. But it might be a core issue rather than a annotations one.

It is not possible to explicit the PK

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 11:36 am 
Beginner
Beginner

Joined: Fri Nov 21, 2003 4:50 am
Posts: 23
emmanuel wrote:
I think this is a bug, since we might add child_id in the PK. But it might be a core issue rather than a annotations one.


So should I add an issue to jira?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 6:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
yes, i need it as a reminder.
Note that you can define the DDL yourself and choose the PK you want

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.