-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problems reverse engineering database
PostPosted: Tue Jun 05, 2012 4:05 pm 
Newbie

Joined: Tue Jun 05, 2012 3:18 pm
Posts: 1
Hi,

I'm trying to reverse engineer our database, and I'm running into two problems.

1) Need to add allocationSize=1 to the sequence generator annotation.
I'm trying to reverse engineer my Oracle db which uses sequences. I get very funky behavior if I don't add allocationSize=1. It starts the numbering at a negative number, and it won't advance past existing rows when the sequence number hits an existing row. It's as if Hibernate is ignoring the sequence. I do see the call to nextval in the logs. Selecting the nextval in a SQL editor returns the correct sequence, but Hibernate never seems to get on track unless I add the allocationSize. The code that is generated is

Code:
   
        @SequenceGenerator(name = "generator", sequenceName = "TYPE_TYPE_ID_SEQ1")
   @Id
   @GeneratedValue(strategy = SEQUENCE, generator = "generator")
   @Column(name = "TYPE_TYPE_ID", unique = true, nullable = false, precision = 22, scale = 0)
   public Long getId() {
      return this.id;
   }


What I'd like to see is

Code:
   
        @SequenceGenerator(name = "generator", sequenceName = "TYPE_TYPE_ID_SEQ1", allocationSize=1)
   @Id
   @GeneratedValue(strategy = SEQUENCE, generator = "generator")
   @Column(name = "TYPE_TYPE_ID", unique = true, nullable = false, precision = 22, scale = 0)
   public Long getId() {
      return this.id;
   }


The definition in my hibernate.reveng.xml file for this table is

Code:
<table name="TYPE_TYPE" class="TypeType">
   <primary-key>
     <generator class="sequence">
       <param name="sequence">TYPE_TYPE_ID_SEQ1</param>
     </generator>
     <key-column name="TYPE_TYPE_ID" property="id" type="Long"/>
   </primary-key>
   <column name="TYPE_TYPE_NAME" property="name" type="string"></column>
</table>


Can this be done in hibernate.reveng.xml, or do I need to do this in a reverse engineering strategy? If it has to be done in a strategy, how would I do this? All I've found is articles on how to change the column name.

2) Hibernate seems to be ignoring my names for foreign keys. For example in my hibernate.reveng.xml file I have (some columns deleted fro brevity)

Code:
   <table name="METH_STRM" class="MethodStream">
      <primary-key>
        <generator class="sequence">
          <param name="sequence">METH_STRM_ID_SEQ1</param>
        </generator>
        <key-column name="METH_STRM_ID" property="id" type="Long"/>
      </primary-key>
      <column name="ATTR_TYPE_ID" property="attributeTypeId" type="Long"></column>
      <column name="VAL_TYPE_ID" property="valueTypeId" type="Long"></column>
      <column name="DPRD_TYPE_ID" property="dataProductTypeId" type="Long"></column>
   </table>


and Hibernate generates

Code:
@Entity
@Table(name = "METH_STRM")
public class MethodStream implements java.io.Serializable {

   private Long id;
   private Type typeByDprdTypeId;
   private Type typeByValTypeId;
   private Type typeByAttrTypeId;
...


I would have expected dataProductTypeId or dataProductType, but I'm not sure why it's completely ignoring the name I provided. How do I modify my xml so it doesn't ignore the name?


Any help would be appreciated! Thanks!


Top
 Profile  
 
 Post subject: Re: Problems reverse engineering database
PostPosted: Mon Jun 11, 2012 6:52 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
What database are you using?
Sequences are deeply database-dependent.

It's also possible the reveng simply doesn't handle that specific option. In that case, you'll probably use reveng just to generate an initial set of classes, and continue to maintain the classes by hand.
(I strongly suspect that Hibernate Tools aren't being maintained anymore. If that's true, their usefulness is dwindling with every new release of Hibernate - already they can't generate code for Hibernate 4.x.)


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