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.  [ 3 posts ] 
Author Message
 Post subject: Something like bug.
PostPosted: Mon Jul 28, 2008 5:11 am 
Newbie

Joined: Sun Mar 19, 2006 4:18 pm
Posts: 17
Location: Turkey
Hibernate tools version: Hibernate Tools 3.2.1.GA

Hi,
I have a table like this,

tableA
col_a
col_b,
col_c,
primary key col_a,
foreign key col_b reference table_b,
foreign key col_b, col_c reference table_c

tableB
col_b,
...
primary key col_b,
...

tableC
col_b,
col_c,
...
primary key col_b, col_c


Hibernate tools generated entity bean for tableA is like this;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "col_b", nullable = false)
public TableB getTableB() {
return this.tableB;
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns( {
@JoinColumn(name = "col_b", referencedColumnName = "col_b", nullable = false, insertable = false, updatable = false),
@JoinColumn(name = "col_c", referencedColumnName = "col_c", nullable = false, insertable = false, updatable = false) })
public TableC getTableC() {
return this.tableC;
}

But it have to be like this;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "col_b", nullable = false, insertable = false, updatable = false)
public TableB getTableB() {
return this.tableB;
}


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns( {
@JoinColumn(name = "col_b", referencedColumnName = "col_b", nullable = false),
@JoinColumn(name = "col_c", referencedColumnName = "col_c", nullable = false) })
public TableC getTableC() {
return this.tableC;
}

Because one of them covers another.

I think this have to be fixed.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 28, 2008 9:08 am 
Newbie

Joined: Sun Mar 19, 2006 4:18 pm
Posts: 17
Location: Turkey
And also, Hibernate tools genereted home class,

I needed to change home class remove function,
Code:
   public void remove(PrWorksheet persistentInstance) {
      log.debug("removing PrWorksheet instance");
      try {
         entityManager.remove(persistentInstance);
         log.debug("remove successful");
      } catch (RuntimeException re) {
         log.error("remove failed", re);
         throw re;
      }
   }

to the;
Code:
   public void remove(PrWorksheet persistentInstance) {
      log.debug("removing PrWorksheet instance");
      try {
         persistentInstance = entityManager.find(PrWorksheet.class, persistentInstance.getSeqno());
         entityManager.remove(persistentInstance);
         log.debug("remove successful");
      } catch (RuntimeException re) {
         log.error("remove failed", re);
         throw re;
      }
   }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 8:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
about the mapping then that sounds like a case where you should not use reverse engineering since its a very special case. Which one of those two asscoations should "win" ?

the remove method does not need changing if you are using a conversation scoped entityManager.

_________________
Max
Don't forget to rate


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