-->
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: net.sf.hibernate.exception.ConstraintViolationException
PostPosted: Thu Nov 24, 2005 8:34 am 
Newbie

Joined: Thu Nov 24, 2005 8:17 am
Posts: 10
Hi ,
I am completly new to Hibernate, I was trying a sample example.

I have a table called Login on SQL server 2000.
When i try to save the records ,

//CODE

Login log=new Login();
log.setUsername("USER");
log.setPassword("PWD");
session.save(log);
tx.commit();

//END OF CODE



it throws me the below exception


net.sf.hibernate.exception.ConstraintViolationException: could not insert: [org.Login]
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:62)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at net.sf.hibernate.persister.AbstractEntityPersister.convert(AbstractEntityPersister.java:1331)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:540)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:426)
at net.sf.hibernate.impl.ScheduledIdentityInsertion.execute(ScheduledIdentityInsertion.java:28)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2449)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:943)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:868)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:786)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:749)
at org.Test.main(Test.java:26)
Caused by: com.inet.tds.SQLException: Msg 515, Level 16, State 2, Line 1, Sqlstate 23000
[AEDXB-ASHKAR]Cannot insert the value NULL into column 'UserName', table 'Telecom_HelpDesk.dbo.Login'; column does not allow nulls. INSERT fails.
at com.inet.tds.q.a(Unknown Source)
at com.inet.tds.a.a(Unknown Source)
at com.inet.tds.k.a(Unknown Source)
at com.inet.tds.k.a(Unknown Source)
at com.inet.tds.k.b(Unknown Source)
at com.inet.tds.d.f(Unknown Source)
at com.inet.tds.d.execute(Unknown Source)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:502)
... 8 more


My Mapping XML IS

<hibernate-mapping package="org">

<class name="Login" table="Login">


<id name="username" column="UserName" type="string">
<generator class="native"/>
</id>

<property name="password" column="Password" type="string" />
</class>

</hibernate-mapping>

I can retrive records but cannot save
Please Help.

Thanks a million in Advance


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 8:38 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Please follow the "Introduction to Hibernate" tutorial that comes with the Hibernate package, first chapter reference documentation. Use Hibernate 3.1 rc3.


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.