-->
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: How to set generator from ReverseEngineeringStrategy?
PostPosted: Tue Jun 22, 2010 12:10 pm 
Newbie

Joined: Mon Aug 18, 2008 10:54 am
Posts: 11
Location: Devon, UK
Can someone explain briefly how I can set the generator for a primary key column from a ReverseEngineeringStrategy?

I am extending DelegatingReverseEngineeringStrategy, but cannot see how to manipulate the generator for a primary key column.

e.g. Hibernate is generating hbm like this -

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 22-Jun-2010 17:07:47 by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
<class name="uk.co.accountablecare.web.orm.generated.Test" table="test" schema="public">
<id name="id" type="int">
<column name="id" />
<generator class="assigned" />
</id>


But that is not correct for my purposes. I am Using Postgres 8.4.4 and the column is of a "serial" type, which whilst an int, it is also generated by the database. I need to produce hibernate to produce hbm's that set the generator class to sequence. e.g. -

<hibernate-mapping>
<class name="uk.co.accountablecare.web.orm.generated.Test" table="test" schema="public">
<id name="id" type="int">
<column name="id" />
<generator class=""sequence">
<param name="sequence">test_id_seq</param>
</generator>
</id>



So how can I manipulate the generator class and its parameters from the ReverseEngineeringStrategy please?

Thanks Adam.

_________________
Adam Retter


Top
 Profile  
 
 Post subject: Re: How to set generator from ReverseEngineeringStrategy?
PostPosted: Wed Jun 23, 2010 4:13 pm 
Newbie

Joined: Mon Aug 18, 2008 10:54 am
Posts: 11
Location: Devon, UK
Thanks, but I am already aware of that! My question was how to do it from the ReverseEngineeringStrategy?

_________________
Adam Retter


Top
 Profile  
 
 Post subject: Re: How to set generator from ReverseEngineeringStrategy?
PostPosted: Mon Jun 28, 2010 7:29 am 
Newbie

Joined: Mon Aug 18, 2008 10:54 am
Posts: 11
Location: Devon, UK
That works nicely, thanks :-)

_________________
Adam Retter


Top
 Profile  
 
 Post subject: Re: How to set generator from ReverseEngineeringStrategy?
PostPosted: Tue Mar 01, 2011 7:13 am 
Beginner
Beginner

Joined: Tue Dec 21, 2010 5:26 am
Posts: 25
"This looks interesting", is what I though when coming across this thread. Another person who has the same trouble with the custom reveng strategy. And then, the last post

Quote:
That works nicely, thanks :-)


"Great", I thought... Tried it and oh wonder: It doesn't effing work either! What is it with "features" in this that don't work either way you try them?

Always the same error:
Code:
org.hibernate.console.HibernateConsoleRuntimeException: Could not create or find CustomRevEngStrategy with one argument delegate constructor


Top
 Profile  
 
 Post subject: Re: How to set generator from ReverseEngineeringStrategy?
PostPosted: Tue Mar 01, 2011 3:31 pm 
Newbie

Joined: Mon Aug 18, 2008 10:54 am
Posts: 11
Location: Devon, UK
I think your constructor is wrong, probably also the one in the example code in this thread. I may have just done this without thinking or mentioning it. Try this --

public CustomReverseEngineeringStrateg(ReverseEngineeringStrategy delegate) {
super(delegate);
}

_________________
Adam Retter


Top
 Profile  
 
 Post subject: Re: How to set generator from ReverseEngineeringStrategy?
PostPosted: Wed Mar 02, 2011 3:13 am 
Beginner
Beginner

Joined: Tue Dec 21, 2010 5:26 am
Posts: 25
Thanks for the reply. But, there's nothing wrong with the constructor. In fact, if there were, the compiler would give you an error:
Code:
Implicit super constructor DelegatingReverseEngineeringStrategy() is undefined. Must explicitly invoke another constructor

if you only define a standard constructor like public CustomRevEngStrategy(){}

or

Code:
Implicit super constructor DelegatingReverseEngineeringStrategy() is undefined for default constructor. Must define an explicit constructor

if you don't define any constructor at all

Again, thanks for trying to help, but my code looks exactly like yours does.


Top
 Profile  
 
 Post subject: Re: How to set generator from ReverseEngineeringStrategy?
PostPosted: Wed Mar 02, 2011 4:10 am 
Newbie

Joined: Mon Aug 18, 2008 10:54 am
Posts: 11
Location: Devon, UK
Ah right!

So it sounds to me like there is something wrong in how you configure Hibernate to find your Reverse Engineering Strategy. I dont know what mechanism you are using, personally I am using Maven and have this as a step in my build process. For reference, it looks like this -

<plugin id="prepare">
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<componentProperties>
<reversestrategy>uk.org.adamretter.hibernate.reveng.interfacestratergy.InterfaceReverseEngineeringStrategy</reversestrategy>
<packagename>uk.co.accountablecare.web.orm.generated</packagename>
<propertyfile>src/main/resources/hibernate.properties</propertyfile>
</componentProperties>
</configuration>
<executions>
<execution id="prepare">
<phase>initialize</phase>
<goals>
<goal>hbm2cfgxml</goal>
<goal>hbm2hbmxml</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.4-702.jdbc4</version>
</dependency>
<dependency>
<groupId>uk.org.adamretter.hibernate.reveng</groupId>
<artifactId>hibernate-interface-strategy</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.2.4.GA</version>
</dependency>
</dependencies>
</plugin>

_________________
Adam Retter


Top
 Profile  
 
 Post subject: Re: How to set generator from ReverseEngineeringStrategy?
PostPosted: Wed Mar 02, 2011 7:17 am 
Beginner
Beginner

Joined: Tue Dec 21, 2010 5:26 am
Posts: 25
I don't know jack about Maven. Quite frankly, I'm happy that my company rejects it. Don't see what it has to do with Hibernate's ReverseEngineering, anyhow.

I'm using the Hibernate-Tools with the Eclipse plugin. In the "Hibernate Code Generation Configurations..." wizard I set the field "reveng.strategy" to my custom class. I am under the impression that this is the way to do it. (I mean, what else would this be for?)


Top
 Profile  
 
 Post subject: Re: How to set generator from ReverseEngineeringStrategy?
PostPosted: Thu Mar 03, 2011 3:04 am 
Beginner
Beginner

Joined: Tue Dec 21, 2010 5:26 am
Posts: 25
Turned out, that is the way to do it. But, what you can hardly read anywhere is: This perticular class has to be in the class path of the Hibernate Configuration. And for anyone like me who doesn't know what that is: that is not necessarily the project you're currently working in! It is the project for which you originally created the configuration (That thing you can see using the Hibernate Perspective).

Since you need to browse to an existing project when creating such a new configuration, this project's class path is the same the new hibernate configuration will use... At least that's how it seems to me.

So I copied the file to a package in this project and: it works. Finally!

Thannks for helping


Top
 Profile  
 
 Post subject: Re: How to set generator from ReverseEngineeringStrategy?
PostPosted: Sun Apr 10, 2011 4:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
X5-599 wrote:
Turned out, that is the way to do it. But, what you can hardly read anywhere is: This perticular class has to be in the class path of the Hibernate Configuration. And for anyone like me who doesn't know what that is: that is not necessarily the project you're currently working in! It is the project for which you originally created the configuration (That thing you can see using the Hibernate Perspective).

Since you need to browse to an existing project when creating such a new configuration, this project's class path is the same the new hibernate configuration will use... At least that's how it seems to me.

So I copied the file to a package in this project and: it works. Finally!

Thannks for helping


You don't have to choose a project. That is just optional.
http://docs.jboss.org/tools/3.0.0.CR1/e ... nsole_conf explains both project reference and the class path tab.

_________________
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.  [ 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.