-->
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.  [ 12 posts ] 
Author Message
 Post subject: handle PK flds in PostGreSQL differently with eclipse tool
PostPosted: Mon Sep 05, 2005 5:56 am 
Newbie

Joined: Fri Sep 02, 2005 6:03 pm
Posts: 13
Hibernate version: 3.0

Name and version of the database you are using: PostGreSQL v8.0.1

Right now, the "Hibernate Artifact Generation" eclipse plug-in produces:

Code:
        <id name="id" type="integer">
            <column name="id" />
            <generator class="assigned" />
        </id>

for primary key fields in my PostgreSQL tables.

I'd like it to produce:

Code:
        <id name="id" type="integer" column="id">
            <generator class="sequence">
               <param name="sequence">[name of table here]_id_seq</param>
            </generator>
        </id>

Using the latter xml in my mapping files yields exactly the behavior I'm looking for on the part of Hibernate. I'd like to skip all of the hand-editing I need to do every time I change/add a table, if I can.

The doco (http://www.hibernate.org/hib_docs/tools/ant/index.html#gen13 ) I've read talks about implementing ReverseEngineeringStrategy and creating my own way of handling this particular situation. I don't have that interface in my distro but I'm sure I can get it out of CVS.

Is the reverse-engineering extensibility only available via ANT or will it work with the eclipse plug-in, too? If so, what changes are needed within the cfg files to allow Hibernate to find my ReverseEngineeringStrategy implementor (or DelegatingReverseEngineeringStrategy) class?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 8:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
http://opensource2.atlassian.com/projec ... se/HBX-389

we cant specify the reveng startegy in the ui yet - will do that at some point (hopefully soon ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 12:33 pm 
Newbie

Joined: Fri Sep 02, 2005 6:03 pm
Posts: 13
Can you point me at more info about how to use it with Ant? I've only found one blurb about reveng extensibility in the doco so far.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 1:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
http://www.hibernate.org/hib_docs/tools/ant/index.html

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 2:04 am 
Newbie

Joined: Fri Sep 02, 2005 6:03 pm
Posts: 13
Haven't been able to make the prescribed way work so far. In the meantime, I've kludge together an XML fixer that does what I need.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 2:05 am 
Newbie

Joined: Fri Sep 02, 2005 6:03 pm
Posts: 13
...haven't been able to make the prescribed way work so far. In the meantime, I've kludged together an XML fixer that does what I need.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 06, 2006 6:58 pm 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
Hi, I want to do the exact same thing as kheston, in other words produce primary keys like this:

Code:
<id name="id" type="integer" column="id">
<generator class="sequence">
<param name="sequence">[name of table here]_id_seq</param>
</generator>
</id>


I just can't see the method I am supposed to override, and how to implement it and I can't find any examples...

The cvs files can be found here kheston:
http://cvs.sourceforge.net/viewcvs.py/h ... fg/reveng/

Code:
import org.hibernate.cfg.reveng.* ;
import java.util.Properties;


public class SerialForPostgres extends DelegatingReverseEngineeringStrategy  {

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

   public Properties getTableIdentifierProperties(TableIdentifier ti) {
      Properties prop = new Properties();
      return null;
   }

}


I was wondering if it might be the getTableIdentifierProperties method I should implement, but if it is, I have no idea how..

Thanks for the help in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 06, 2006 7:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Code:
public Properties getTableIdentifierProperties(TableIdentifier ti) {
      Properties prop = new Properties();
      prop.setProperty("sequence", ti.getName() + "_id_seq";
      return null;
   }

public String getTableIdentifierStrategyName(TableIdentifier identifier) {
  return "sequence";
}

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 06, 2006 8:23 pm 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
Thanks, that was just what I needed!

if you are using the following format for createing your tables:

create table tablename (
tablename+"id" serial PRIMARY KEY NOT NULL,
...
);

this code will create the correct indexes
Code:
public class SerialForPostgres extends DelegatingReverseEngineeringStrategy  {

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

   public Properties getTableIdentifierProperties(TableIdentifier ti) {
      Properties prop = new Properties();
      prop.setProperty("sequence", ti.getName()+"_"+ ti.getName()+ "id_seq");
      return prop;
   }

   public String getTableIdentifierStrategyName(TableIdentifier identifier) {
      return "sequence";
   }

}


Maybe you should add a hint somewhere in the tools that this is the way to do it if you are using postgres with serial? There can't be a more than a handful of postgres+hibernate users that haven't had the same problem that this solves...

.. And I must say that I couldn't have gotten better support if I had payed for it :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 06, 2006 8:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Quote:
.. And I must say that I couldn't have gotten better support if I had payed for it :)


Then have the decency to contribute something back, e.g. a patch to the docs ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 2:07 pm 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
I had a little look around, but couldn't find out how to contribute...

I would be interested in contributing, because it must be annoying to all the postgres users out there ;)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 2:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
just check out the docs from cvs and make a patch and put it in jira - easy, eh ? :)

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