-->
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: orm.xml <generated-value>
PostPosted: Thu Dec 13, 2007 9:58 am 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
Hey all,

Trying to use Hibernate JPA adapter in Spring 2.0.6 with a MS SQL 2000 database and jtds 1.2 driver. Hibernate Entity Manager 3.3.1/core 3.2.4/annotations 3.3

Using non-annotated dto bean, I'm placing all the JPA information in the orm.xml. The one thing that I am a complete idiot on (it's been 1/2 a day, and I can't get it) is a database-maintained primary key (i.e. auto id).

<attributes>
<id name="userId">
<column name="USER_ID"/>
<!--
<column name="USER_ID" column-definition="int identity"/>
<generated-value strategy="IDENTITY" />
<generated-value strategy="AUTO" />
-->
</id>

I've tried access=FIELD, PROPERTY different generated-value, no generated-value, and nothing is working.

I keep getting 'Parameter #14' is missing (which is the USER_ID field in the SQLshow statement).

I keep getting 'Can not explicit insert when IDENTITY_INSERT is off' in other scenarios (as I keep trying things to get this to work).

What the heck are you supposed to do for the above environment?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 15, 2007 9:49 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
<id name="userId">
<column name="USER_ID"/>
<generated-value strategy="AUTO" />
</id>


looks like the right think to do.
Are you letting hibernate generate the DB schema? This is the most likely issue

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 17, 2007 2:42 pm 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
Actually, I am reverse engineering from an existing DB Schema.

As a side-issue, I had to use OpenJPA to reverse engineer the schema as I want java 1.4 DTO with the orm.xml mapping file. I could not find a way to do this with the hibernate tools.

*Please confirm that hibernate-tools can not reverse engineer java 1.4 DTO with orm.xml mapping file.

Secondly, there seems to be some issues with MS SQL and auto-id fields. I'm not sure what it is, but apparently there have been a couple of issues on various mailing lists (both jtds and other jdbc drivers) with it.

As for Spring framework, I could not do anything with MS SQL with the hibernate JPA adaptor, nor with OpenJPA or Toplink. I had success with MySQL, but not MS SQL my target DB. I've changed to directly use the Hibernate EntityManager (which is better for my use-case anyway), but still have issues with the MS SQL auto-id fields.

As a work-around, I'm using <table-generator> in my orm.xml file to bypass MS SQL's identity issue while using Hibernate EntityManager directly. If more info on MS SQL identity and/or reverse engineering with orm.xml is available, that would be greatly appreciated!!

-D


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 22, 2007 5:06 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No I don't think our tools support this case. It's too odd :) You can use the hbm.xml generation but you probably don't want that.
Use Microsoft JDBC driver, the last versions are very good.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 1:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
*Please confirm that hibernate-tools can not reverse engineer java 1.4 DTO with orm.xml mapping file.

I have no idea what that means, could you elaborate.

(my guess is you are asking for if we can generate dto/pojos without annotations when using existing entities - then yes, that is possible just dont set java5 to true for the relevant exporter)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 3:11 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Max he wants you to generate the orm.xml rather than annotations. We don't support this case I think.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 4:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ah no - orm.xml is not something we generate.

Noone never asked nor contributed anything like it before. Very doable though; but not sure how relevant that usecase is.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 4:35 pm 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
My use-case is indeed to reverse engineer from an existing database schema, to generate the java DTO's without annotations, and soley use orm.xml.

This scenario is extremely useful for Data-Transport Objects in multi-client environments, where if you use an annotation, you may/will need to include the hibernate-annotations.jar for client-code to compile correctly. By using orm.xml and no annotations, you can safely avoid this scenario.

The most recent/popular use-case client for this is GWT (1.4) where the client does not support annotations at all. This approach has proven to work great, just automation is difficult with the hibernate tools, but is possible with the OpenJPA tools.

Other scenarios are Eclipse RCP, or even Swing applications written to run on older JDK (as old as JDK 1.3 actually).

Yes, you can say wait for GWT 1.5, but that does not solve the problem of supporting orm.xml implementations and other client technologies that may not like or appreciate annotations.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 4:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
dhartford wrote:
My use-case is indeed to reverse engineer from an existing database schema, to generate the java DTO's without annotations, and soley use orm.xml.


if by DTO you mean the entity then sure; that is doable today.

Quote:
This scenario is extremely useful for Data-Transport Objects in multi-client environments, where if you use an annotation, you may/will need to include the hibernate-annotations.jar for client-code to compile correctly. By using orm.xml and no annotations, you can safely avoid this scenario.


well, i fail to see how depending on hibernate-annotations.jar at compile time is bad when you definitly need it at runtime if you are going to use Hibernate/JPA.

Quote:
The most recent/popular use-case client for this is GWT (1.4) where the client does not support annotations at all. This approach has proven to work great, just automation is difficult with the hibernate tools, but is possible with the OpenJPA tools.


Automatiation ? You wan't to rely on purely reveng code ? Not good imo ;)

But anyhow, you are saying that openjpa tools supports generating orm.xml's ? Interesting. Feel like contributing something like that to hibernate tools ?

Quote:
Other scenarios are Eclipse RCP, or even Swing applications written to run on older JDK (as old as JDK 1.3 actually).


Using retroweaver should be a possibility here..

Quote:
Yes, you can say wait for GWT 1.5, but that does not solve the problem of supporting orm.xml implementations and other client technologies that may not like or appreciate annotations.


I understand your usecase but I do not understand why blind reverse engineering is ok by you...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 4:57 pm 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
The reverse engineering is simply to bootstrap. Even with OpenJPA, I keep the /generated separate from my /src/java code, and simply have the generated java entities and associated orm.xml to bootstrap 80% of the java and orm.xml, then modify only small amounts.

OpenJPA has a reverse-customizer.properties file to fine-tune reverse engineering.

As to completely relying on reverse engineering, yes, that is a bad idea, but if you can get 80% bootstrapped, when you are dealing with even just 10 tables, writing the java entities and associated orm.xml file and relation mappings would take up to 8 hours compared to couple minutes reverse engineered.

I'm sorry, I did not intend to express reverse engineering as the 'best' option, but simply something that is extremely time-saving when dealing with existing Database Structures.

Alas, this is my real-world use case ;-)

edit: I did look into hibernate4gwt, dozer, apache beanlib, and similar tools, but I wanted to avoid the creation of additional libraries to manage.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 04, 2008 3:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Understood.

The problem with orm.xml is that it does not enable you to use the full range of hibernates functionallity so using hbm.xml's would be more sensible. And since you are already depending on hibernate-annotations.jar you are already outside the domain of the JPA spec.

If you truly still wan't orm.xml generation support I would gladly accept patches for an orm.xml exporter.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: orm.xml <generated-value>
PostPosted: Tue Oct 22, 2013 5:59 pm 
Newbie

Joined: Tue Oct 22, 2013 5:42 pm
Posts: 1
According to this stackoverflow answer:
http://stackoverflow.com/a/3808406/1378620

I am quoting from the answer wrote:
However, if you were using Hibernate Proprietary API and already have a hibernate.cfg.xml (and hbm.xml XML mapping files) but want to start using JPA, you can reuse the existing configuration files by referencing the hibernate.cfg.xml in the persistence.xml in the hibernate.ejb.cfgfile property - and thus have both files.


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.