-->
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.  [ 30 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: how to create sequences for assigned ID's - solved
PostPosted: Mon Aug 28, 2006 10:59 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1.2

Mapping documents:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
<class
name="net.sourceforge.lebon.model.VotingRight"
table="VotingRight"
>

<id
name="id"
column="ID"
type="java.lang.Long"
>
<generator class="assigned">
<param name="sequence">VTR_SEQ</param>
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-VotingRight.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<timestamp
name="modifiedAt"
column="modified_at"
access="property"
unsaved-value="null"
/>

<property
name="amount"
type="java.lang.Float"
update="true"
insert="true"
column="amount"
not-null="true"
/>

<property
name="modifiedBy"
type="java.lang.String"
update="true"
insert="true"
column="modified_by"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-VotingRight.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


Hello,

I am moving a project to sequences and I need the ID generator class to be assigned so that I can assign the ID right after creating the entity object (I can't change that)..

The problem is hbm2ddl dosen't generate the "create sequence" part if the generator class isn't "sequence" (or that's how thing look at the moment)

So can anybody tell me how to "convince" hbm2ddl to generate something like this
Code:
     insert into dual_USR_SEQ values (0);

    create sequence USR_SEQ start with 1;

    create table dual_VTR_SEQ (
        zero integer
    );

while using assigned as id class generator ?

thank you


Last edited by sorin7486 on Thu Aug 31, 2006 8:33 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 28, 2006 12:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
<database-object>

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 3:42 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
Thank you again for the quick response.. guess I'll have to start reading on those docs because the book I use fails to mention this....

for those with similar problems I am generating the .hbm's from the entity model using xdoclet and from that i generate the .ddl . So I decided to write a custom class to generate the create for sequences...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 3:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
its a "newish" feature. in the reference doc.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 9:52 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
Well.. sadly I didn't got far on that....

I am working on the custom class (extending AuxiliaryDatabaseObject)... and I can't find any information about it... My question: is there any way to find out from there information about the mappings... The only useful thing I see is a Mapping object but I can't figure out how to get the info from it (other than the ID name and type)... Do I have to manualy read the .xml mapping files ? or is there another way ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 9:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
eh - you just write the sql you want in there.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 9:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you could always do something like cfg.addAuxilaryObject(ao); where ao knwos about the cfg.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 12:03 pm 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
I know i can just put the sql there... what I want is to write a method that wold look at the mapping and just add the necessary sql ... what do you mean by "cfg.addAuxilaryObject(ao)" ??? i don't understand that....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 1:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Code:
  Configuration cfg = ....
  YourAO ao = new YourAO(cfg);
  cfg.addAuxilaryObject(ao);


now your ao knows about the ao and can do what it want.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 4:08 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
my problem is not getting the AO in the cfg ... but the other way arround... how do i retrieve the Configuration object used by hbm2ddl so that I can access the information I need about the entitys (this hapens at mvn compile time) ???

Can I do this or do I have to make a new Configuration object and load everything in it ???


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 4:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
huh ? didn't you read my code ?

You pass the cfg into the constructor or method of your own AO and then you got all the info you need.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 4:28 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
Configuration cfg = ????

do I just do "new Configuration" or is there a container from witch I can get the cfg like obj.getConfiguration()... Don't I need the instance of the object that hbm2ddl created ????


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 4:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
where do you get a Configuration from today ?

...i'm talking about solving this programmatically since the mapping filesl nor the AuxillaryObject do not provide the means for you to get the Configuration.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 4:57 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
right now I use Configuration in the SessionFactory(to generate it)... and the SessionFactory is created by Spring...

But that dosen't work at compilation(that's when I create the ddl file).. I presume hbm2ddl creates it's own Configuration object... and I presume I can't get that do I ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 5:00 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
Could I add at runtime the necessary stuff to the SQL by using the Configuration in the SessionFactory?? was that what you where trying to explain ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 30 posts ]  Go to page 1, 2  Next

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.