-->
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: mapping of Oracle NUMBER for identifiers and columns
PostPosted: Wed Sep 07, 2011 8:56 am 
Newbie

Joined: Thu Oct 23, 2003 8:19 am
Posts: 14
Location: Tampa, FL USA
I'm using Entity Manager 3.6.6 and I'm working on generating entities from tables with Dali in Eclipse.

I have tables that look something like this:

Code:
CREATE TABLE person (
   id              NUMBER(22,0)  PRIMARY KEY,
   name         VARCHAR(20),
   gender_id   NUMBER(22,0)  NOT NULL,
   address_id  NUMBER(22,0)
)


There is a gender table without a foreign key constraint as it is turned into an enumerations later. Hence, my desire for a Basic mapping type on that field, and not a One-to-One to the gender table.

My problem is that the id becomes type long, and the gender_id and address_id become type BigDecimal. It would seem that this is the expected behavior of the "sequence" and "hilo" id generators. I kinda wanted to use "sequence".

If I include the gender and address tables into the entity generation process, the gender_id and address_id will get generated as long, and not BigDecimal. I presume this is because of the id generation requirement for long on those tables.

If I don't select to create entities for gender and address, I will be presented with the option to set the basic type of the address_id. I WON'T be presented with the option to change the basic type of gender_id. I'm starting to think this is a bug in Dali regarding the "NOT NULL".

Is there a way for me to globally ensure that all NUMBER(22,0) database types get mapped to type long?


Top
 Profile  
 
 Post subject: Re: mapping of Oracle NUMBER for identifiers and columns
PostPosted: Wed Sep 07, 2011 1:11 pm 
Newbie

Joined: Thu Oct 23, 2003 8:19 am
Posts: 14
Location: Tampa, FL USA
I ended up using Hibernate Tools from within Maven. Like this:

Code:
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
               <execution>
                  <phase>generate-sources</phase>
                  <goals>
                     <goal>run</goal>
                  </goals>
                  <configuration>
                     <tasks>
                        <taskdef
                           name="hibernatetool"
                           classname="org.hibernate.tool.ant.HibernateToolTask"
                           classpathref="maven.test.classpath">
                           <classpath>
                              <pathelement location="src/main/build/resources"/>
                           </classpath>
                        </taskdef>
                        <mkdir dir="target/generated-sources/hbm2java"/>
                        <hibernatetool destdir="target/generated-sources/hbm2java">
                           <jdbcconfiguration
                              propertyfile="src/main/build/resources/hibernate.properties"
                              packagename="com.example.entity.generated"
                              revengfile="src/main/build/resources/hibernate.reveng.xml"
                           />
                           <hbm2java
                              jdk5="true"
                              ejb3="true"
                           />
                        </hibernatetool>
                     </tasks>
                  </configuration>
               </execution>
            </executions>
         </plugin>


where the hibernate.reveng.xml file looks like this:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering
  SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>

   <type-mapping>
      <sql-type jdbc-type="DECIMAL" precision="22" scale="0" hibernate-type="long" />
   </type-mapping>

   <table-filter match-name="PERSON" exclude="false"/>

</hibernate-reverse-engineering>


works pretty nicely!


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.