-->
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.  [ 7 posts ] 
Author Message
 Post subject: ORA-01400 when identifier set by application
PostPosted: Mon Aug 23, 2010 10:36 am 
Newbie

Joined: Mon Aug 23, 2010 6:34 am
Posts: 6
Hi!

I use Spring 3 and Hibernate 3. and have the following problem:

This is a piece of my class I want to persist
Code:
@Id
private String id;

public String getId() {
   return this.id;
}

public void setId(String id) {
   this.id = id;
}


In my test method I set the id and persist my object via

Code:
hibernateTemplate.save(object)


When I start this test I get
Code:
ORA-01400: Cannot insert null [...]


It's strange, because, when I remove the @Id annotation and define another property as identifier, which is generated by Hibernate, everything works fine.
Does anybody know what's going on?
Any help is appreciated :)


Top
 Profile  
 
 Post subject: Re: ORA-01400 when identifier set by application
PostPosted: Mon Aug 23, 2010 1:56 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Code:
@Id
private String id;


Since it is a String you either need to assign your own id or specify a generator that know how to generate string values. The standard ones in JPA only works with numbers, but Hibernate defines some additional generators. Most of them work with numbers as well, but I think there is one that generates GUID/UUID values. Read http://docs.jboss.org/hibernate/stable/ ... identifier and http://docs.jboss.org/hibernate/stable/ ... aration-id for some more information.


Top
 Profile  
 
 Post subject: Re: ORA-01400 when identifier set by application
PostPosted: Tue Aug 24, 2010 1:56 am 
Newbie

Joined: Mon Aug 23, 2010 6:34 am
Posts: 6
Thanks for your answer :)

As I stated, if I let hibernate generate the Id, it works. But I need to set the Id from the application. But if I assign my own Id via
Code:
object.setId("id1");

the ORA-01400 occurs.


Top
 Profile  
 
 Post subject: Re: ORA-01400 when identifier set by application
PostPosted: Tue Aug 24, 2010 3:02 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I assume that the Id is not included in the SQL because Hibernate thinks the database is going to generate it... You'll probably need to specify that you are using the "assigned" identifier generator.


Top
 Profile  
 
 Post subject: Re: ORA-01400 when identifier set by application
PostPosted: Wed Sep 29, 2010 9:51 am 
Newbie

Joined: Mon Aug 23, 2010 6:34 am
Posts: 6
I tried this:
Code:
@Id
@GenericGenerator(name="name", strategy="assigned")
private String id;


But without succes.
Several pages say, that the simple annotation

Code:
@Id


tells hibernate, that the application takes care of the id.

Now I'm confused. Can somebody shed light on this?

Any help is appreciated. Thank you! :)


Top
 Profile  
 
 Post subject: Re: ORA-01400 when identifier set by application
PostPosted: Wed Sep 29, 2010 2:07 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The default identifier generation strategy is AUTO (http://docs.jboss.org/hibernate/stable/ ... identifier) which means that the database is supposed to generate the id. Exactly how this is done depends on the underlying database.

@GenericGenerator is not enough to specify a different strategy. I think you also need the @GeneratedValue annotation as described here: http://docs.jboss.org/hibernate/stable/ ... identifier


Top
 Profile  
 
 Post subject: Re: ORA-01400 when identifier set by application
PostPosted: Thu Sep 30, 2010 3:08 am 
Newbie

Joined: Mon Aug 23, 2010 6:34 am
Posts: 6
I can't see, that AUTO is the default strategy.

The documentation says
Quote:
This property can be set by the application itself or be generated by Hibernate (preferred).


But it doesn't say how to annotate identifiers, that are set by the application. And the annotation

Code:
@Id
@GeneratedValue


doesn't work either.

And it gets stranger: I have a @OneToMany with a @JoinTable, which contains the primary keys of the related entities.
One of these entities is the one I'm trying to map application generated identifier for. And there are three identifiers:

Code:
@Id
@GeneratedValue
private String id1;
@Id
@GeneratedValue
private String id2;
@Id
@GeneratedValue
private String id3;


But for some reason the JoinTable only contains id2 as identifier for this entity.

Are these errors related?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.