-->
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: Can the hibernate default sequence sql be auto generated?
PostPosted: Fri May 13, 2005 3:34 pm 
Newbie

Joined: Wed Feb 23, 2005 2:08 pm
Posts: 17
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.18

Mapping documents:<hibernate-mapping>
<class name="com.ipds.persistence.ContactType" table="CONTACT_TYPE">
<meta attribute="class-description">
</meta>

<id name="id" type="long" column="CONTACT_TYPE_ID">
<meta attribute="scope-set">protected</meta>
<meta attribute="field-description">Unique identity - automatically generated</meta>
<generator class="native" />
</id>

<property name="type" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">The contact type</meta>
<column name="CONTACT_TYPE" length="40" not-null="true" />
</property>

<property name="lastSaved" type="timestamp">
<meta attribute="field-description">The contact last saved date</meta>
<column name="LAST_SAVED" not-null="true" />
</property>

</class>
</hibernate-mapping>



This is my ant target that I use to generate the ddl for our project. And below is a sample of a typical table create sql statement that is produced. The problem is afterwards I have to insert the sequence sql by hand. Is there a way to do have hiberate do this for me? thanks

Scott



<target name="generate-ddl" depends="copy-mapping" description="generate ddl file">
<tstamp>
<format property="timestamp" pattern="yyyy-MM-dd_hh-mm-ss" />
</tstamp>
<copy file="${basedir}/ddl/ipds-schema.ddl" toFile="${basedir}/ddl/ipds-schema_${timestamp}.ddl" />
<java classname="net.sf.hibernate.tool.hbm2ddl.SchemaExport" fork="true" dir=".">
<arg line="--config=/config/hibernate_ipds.cfg.xml --output=${basedir}/ddl/ipds-schema.ddl --format --text --delimiter=;" />
<classpath refid="hibernate.tools.classpath" />
</java>
</target>

generated sql

create table CONTACT_TYPE (
CONTACT_TYPE_ID int8 not null ,
CONTACT_TYPE varchar(40) not null,
LAST_SAVED timestamp not null,
primary key (CONTACT_TYPE_ID)
);

massaged sql

create table CONTACT_TYPE (
CONTACT_TYPE_ID int8 not null DEFAULT nextval('public.hibernate_sequence'::text),
CONTACT_TYPE varchar(40) not null,
LAST_SAVED timestamp not null,
primary key (CONTACT_TYPE_ID)
);


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 10:40 pm 
Newbie

Joined: Thu May 19, 2005 10:26 pm
Posts: 1
Hibernate 3.0.2

I'm having this issue as well, except I have a bottom-up design without the sequences implented as of yet. I would like to have Hibernate do it instead of creating the DDL. I'm explicitely naming the sequence in the map:

Code:
<id name="id" column="key_allergy_type" type="long">
  <generator class="sequence">
    <param name="sequence">sg_allergy_type_seq</param>
  </generator>           
</id>


I noticed a sqlCreateStrings and sqlDropStrings in the SequenceGenerator class, but don't know how to get Hibernate to call these when the sequence does not exist.


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.