-->
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.  [ 4 posts ] 
Author Message
 Post subject: @ManytoMany with JoinTable:Hibernate creating its own table
PostPosted: Thu Jan 20, 2011 6:26 am 
Newbie

Joined: Sat Jan 01, 2011 4:31 am
Posts: 6
Hi All,
I am using Seam and hibernate and JPA. I am using Seam's EntityHome and EntityQuery classes to do the CRUD operations.
I have a question:
I have two entities with @Entity of JPA API.

I have created two lists of these two entities in each other and annotated like this:

Code:
@Table(name="CLASSA")
Class A{
@Id @GeneratedValue
   @Column(name="CLASSA_ID")
private Long id;

@ManyToMany(cascade=CascadeType.PERSIST)
   @JoinTable(name="CLSA_CLSB",
    joinColumns = {
       @JoinColumn(name = "CLASSA_ID")},
    inverseJoinColumns = {
       @JoinColumn(name = "QID")})
private List<ClassB> classesB= new ArrayList<ClassB>();
}


AND

Code:
@Table(name="CLASSB")
ClassB{
@Id @GeneratedValue
   @Column(name="QID")
    private Long id;
@ManyToMany
    private List<ClassA> classesA;
}

I created the tables myself so instead of naming the jointable as : CLASSA_CLASSB i just named it CLSA_CLSB to keep it short

now the DB is already created, and when I deploy the application on JBOSS hibernate throws an exception that it is missing table: CLASSA_CLASSB,

why is it looking for CLASSA_CLASSB when I have already defined a JOINTABLE. now when i run this on an empty DB with

Code:
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>


it does create the CLSA_CLSB with two fields as in the @MANYTOMANY annotation as well but it also throws an error that CLASSA_CLASSB cannot be created as Identifier (originally the CLASSA and CLASSB are appended with application name so it concatenates both table names which becoems tooo long).

i created the tables with create and then changed the value of the hibernate property to "Update" and I could work and the deployment was successful, BUT when i tried to REMOVE ClassB instances (I was able to create ClassB instances and store them in DB and update them ) it threw me the same error that it cannot find the CLASS_CLASSB table

why is it stuck on this table. why is it even trying to create it in the first place when i have already defined a JOINTABLE. If i keep the property of the hibernate as "validate" then it tries to find the CLASS_CLASSB table which I didnt make nor did i refer it anywhere.

I will really appreciate your help.

Thanks
Syed...


Top
 Profile  
 
 Post subject: Re: @ManytoMany with JoinTable:Hibernate creating its own table
PostPosted: Thu Jan 20, 2011 6:58 am 
Newbie

Joined: Fri May 25, 2007 4:37 am
Posts: 13
Location: Germany
Try

Code:
@Table(name="CLASSA")
ClassA{
@Id @GeneratedValue
@Column(name="CLASSA_ID")
private Long id;

@ManyToMany( cascade={CascadeType.PERSIST, CascadeType.MERGE},
            targetEntity=ClassB.class,)
@JoinTable(name="CLSA_CLSB",
    joinColumns = {
       @JoinColumn(name = "CLASSA_ID")},
    inverseJoinColumns = {
       @JoinColumn(name = "QID")})
private List<ClassB> classesB= new ArrayList<ClassB>();
}


and

Code:
@Table(name="CLASSB")
ClassB{
@Id @GeneratedValue
@Column(name="QID")
private Long id;

@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE},
        mappedBy = "classesB",
        targetEntity = ClassA.class)
private List<ClassA> classesA;
}


See: 2.2.5.3.2. Many-to-many in http://docs.jboss.org/hibernate/stable/ ... ml_single/


Top
 Profile  
 
 Post subject: Re: @ManytoMany with JoinTable:Hibernate creating its own table
PostPosted: Sat Jan 22, 2011 1:23 am 
Newbie

Joined: Sat Jan 01, 2011 4:31 am
Posts: 6
Hi all,

Well for now i have removed the bidirectional and made it only uni directional so i have the manytomany on the classA only.

and now its not looking for that table. its working now. but i havent tested it on concrete data to check th relationship perfectly but I am sure it will work.

Thanks for your help..

Syed


Top
 Profile  
 
 Post subject: Re: @ManytoMany with JoinTable:Hibernate creating its own table
PostPosted: Tue Jan 25, 2011 1:44 am 
Newbie

Joined: Sat Jan 01, 2011 4:31 am
Posts: 6
Ok the @ManyToMany on
Code:
@ManyToMany(cascade=CascadeType.PERSIST)
   @JoinTable(name="CLSA_CLSB",
    joinColumns = {
       @JoinColumn(name = "CLASSA_ID")},
    inverseJoinColumns = {
       @JoinColumn(name = "QID")})
private List<ClassB> classesB= new ArrayList<ClassB>();



and that was it...
actually it was the bidirectional which was causing problems.. It was detecting one table for one directional relationship but for the other directional (on Class_B ) there was no table mapped so it made a new one for that as well.

so that what I did . removed the @manyToMany from the classB and that was it.

Thank for the reply "Konsumierer" really appreciate your help.

Sar


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.