-->
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.  [ 10 posts ] 
Author Message
 Post subject: composite id generation (not as a seperate pojo)
PostPosted: Tue Mar 11, 2008 6:22 am 
Newbie

Joined: Fri Nov 02, 2007 9:28 am
Posts: 8
Hi,

i'm trying to reverse engineer tables using the ant task from a Sybase database, which contains composite Ids as the primary key. Hibernate tools generates the id per default as a seperate id POJO and i would like to have it intergrated in the same POJO.

when running the ant task with the attribute ppreferBasicCompositeids="false" :

<jdbcconfiguration configurationfile="hibernate.cfg.xml" revengfile="../hibernat.reveng.xml" preferBasicCompositeids="false"/>

i got the following exception:
freemarker.core.InvalidReferenceException: Expression pojo.generateManyToOneAnnotation is undefined on line 11, column 3 in pojo/Ejb3PropertyGetAnnotation.ftl.

any pointers on the issue?

thank you very much in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 12:09 pm 
Newbie

Joined: Fri Nov 02, 2007 9:28 am
Posts: 8
any takers?

thank you very much.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 2:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you apparently bumped into a bug in the .ftl files...are these the original ones or are you doing your own templating to support the nested class thing you are doing ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 3:55 am 
Newbie

Joined: Fri Nov 02, 2007 9:28 am
Posts: 8
hi max,

these are the original templates that are being used.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 3:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
then try and track down which table/association combination that triggers this error and report in jira (maybe start by searching jira for it ;)

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Can You Use Eclipse?
PostPosted: Thu Apr 10, 2008 10:15 am 
Newbie

Joined: Tue Apr 01, 2008 3:34 pm
Posts: 10
I was able to generate composite keys using eclipse plugin running against oracle 10g...

You may want to see this post...

http://forum.hibernate.org/viewtopic.php?t=985381&highlight=reveng+notnull+transient

...for an issue I ran into with composite keys and many-to-many relationships. I wasn't able to solve it and haven't had a chance to look further into it. We were able to sway the table design to eliminate the composite keys in favor of sequence/trigger generated simple keys.

My suggestion is to eliminate the composite keys if you can.


Top
 Profile  
 
 Post subject: Re: composite id generation (not as a seperate pojo)
PostPosted: Fri Jul 15, 2011 5:12 am 
Newbie

Joined: Wed Jul 13, 2011 6:55 am
Posts: 4
This bug seems to be still there and appears when a composite id contains foreign keys. Any ideas on how to solve this? I don't know where to start at.


Top
 Profile  
 
 Post subject: Re: composite id generation (not as a seperate pojo)
PostPosted: Tue Jul 19, 2011 4:34 am 
Newbie

Joined: Wed Jul 13, 2011 6:55 am
Posts: 4
The reason for the exception is, in my case, the following:
The element put to the additional context in genericExporter#exportPOJO as "pojo" is, in case of a Composite-ID an instance of ComponentPOJOClass and not EntityPOJOClass. In contrast to EntityPOJOClass, ComponentPOJOClass doesn't contain any methods to generate the assocation annotations like EntityPOJOClass#generateManyToOneAnnotation.

What one can do, is to add those methods (by copying the EntityPOJOClass methods) to ComponentPOJOClass, but I don't know if its intended this way!?

Although I don't have much hope to get any answers: Is this intended? Doesn't Hibernate allow foreign keys in composite ids?


Top
 Profile  
 
 Post subject: Re: composite id generation (not as a seperate pojo)
PostPosted: Mon Sep 05, 2011 11:54 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
I'm using foreign keys just fine.
I'm not sure whether you're really hitting the same issue that was originally reported (my interest in Hibernate has been waning since I'm hitting a wall in support for long-running session, but that's an entirely different story).

Anyway, here's our setup:
We have two tables, ARTDSP, with PK FIRM/STOR/IDENTNR, and ARTSTA, with PK IDENTNR, with the obvious many-to-one FK constraint.
In hibernate.reveng.xml, it looks like this:
Quote:
<table name="ARTDSP">
<foreign-key foreign-table="ARTSTA" constraint-name="fk_artdsp_artsta">
<column-ref local-column="IDENTNR" foreign-column="IDENTNR" />
<many-to-one insert="false" update="false" />
</foreign-key>

We do have our troubles with that.
For one, we needed to carefully code around redundancy: the Artdsp class has both getId().getIdentnr() and getArtsta(); this is not an issue here because IDENTNR is a primary key and you can't call a setter on these without thoroughly confusing Hibernate's dirty checking (it gets confused about the identity of entities since it is using the primary key for that). However, we have FK constraints that are modifiable, and sometimes we have had to make both the raw ID value and the Java pointer available on the POJO side, and you need to be aware that the two need to be updated in lock-step. (Unfortunately, reveng doesn't generate setters that take care of it, and you can't easily subclass the generate code.)
Second, if the constraint is also in the database metadata, you need to use exactly the name that the database uses, else Reveng will think that the constraint in reveng.xml is another, separate one and create TWO links, one for the database one and one for the reveng.xml one. Easy to avoid if you're aware of this, but boy did I have a hard time figuring out why I got
Quote:
Artsta artsta;
Artsta artsta2;
in the generated code!
Third, there is a really fundamental difference between generating inline composite keys or having them separate. Inline keys means that in the above example, I have a firm, a stor, and an identnr field in Artdsp; separate keys means I have a separate ArtdspId class for firm/stor/identnr. Having separate Id objects is nice if you pass ids around a lot, but it sucks if you think at the table field level because the PK fields need to be prefixed with "id." whenever you need them in HQL or a Criteria query (but not if the PK happens to be a single field, in which case Reveng doesn't generate a separate class).

I'm not sure how much of this actually helps you, but here you go :-)


Top
 Profile  
 
 Post subject: Re: composite id generation (not as a seperate pojo)
PostPosted: Mon Apr 06, 2015 9:17 pm 
Newbie

Joined: Wed Jan 02, 2013 5:14 pm
Posts: 2
The best way is to:
- install eclipse plugin (jboss tools)
- create a data base connection.
- create a hibernate console config using the above conn.
- create new hibernate code generation configuration.

If errors out: try to update in market place.

Ref:
https://hop2croft.wordpress.com/2011/05/07/using-hibernate-tools-through-maven-and-ant/


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