-->
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.  [ 6 posts ] 
Author Message
 Post subject: java.sql.BatchUpdateException
PostPosted: Sun Jun 24, 2007 10:48 am 
Newbie

Joined: Sun Jun 24, 2007 10:24 am
Posts: 6
Hi,

Im getting the following exception and am at loss to what I am doing wrong:

java.sql.BatchUpdateException: Field 'fLangId' doesn't have a default value

My db is as follows:

Code:
@Entity @Table(name="tLang")
class Lang:
   @Column(name="fISO639_2")
   @Id
   String _id= null;
   public void setId( String id ) { _id= id; }
   public String getId( ) { return _id; }

   @Column(name="fTitle",nullable=false,length=50,unique=true)
   String _title= null;


Code:
@Entity @Table(name="tContentItem", uniqueConstraints= {@UniqueConstraint(columnNames={"fContentId","fLangId","fMimeTypeId"})})
class ContentItem:
   @ManyToOne
   @JoinColumn(name="fContentId")
   @Column(name="fContentId")
   @Id
   Content _content= null;

   @ManyToOne
   @JoinColumn(name="fLangId")
   @Column(name="fLangId")
   @Id
   Lang lang= null;

   @ManyToOne
   @JoinColumn(name="fMimeTypeId")
   @Column(name="fMimeTypeId")
   @Id
   MimeType _mimeType= null;


An the function that throws the exception is:

Code:
       org.hibernate.Session session= ContentFactory.getSession( );
       org.hibernate.Transaction transaction= session.beginTransaction( );
         Content c= new Content( );
         c.setCreated( date );
         c.setPublished( date );
         c.setTitle( mrequest.getParameter( "title" ) );
         session.save( c );

        ContentItem item= new ContentItem();
         item.setCreated( date );
         item.setContent( c );
         item.setLang( (Lang) session.load( Lang.class, mrequest.getParameter( "lang" ) )  );
         item.setMimeType( (MimeType) session.load( MimeType.class,Long.parseLong( mrequest.getParameter( "mtype" ) ) ) );
         session.save( item );
         session.flush( ); // <<-- Exception thrown
       transaction.commit( );


Ive aldready checked that Lang does indead load correctly. Anyone see what I'm doing wrong here?

cheers,
Magnús Örn Gylfason

Hibernate version: 3.2
Hibernate-annotations version: 3.3.0.GA
MySQL version: 5.038
OS: Ubuntu 7.04
Java version: 1.6.0-b105


Stack trace:
Code:
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)



Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 25, 2007 9:35 am 
Newbie

Joined: Sun Jun 24, 2007 10:24 am
Posts: 6
After doing what I should have done in the first place (logging SQL statemetns) I get this:

Code:
org.hibernate.SQL - insert into tContentItem (fContentDescId, fContentFileId, fCreated, fContentId) values (?, ?, ?, ?)


Obviously fLangId is missing from that insert statement. Also missing is fMimeTypeId which is a part of the key and would have been my next exception. Is it multiple @Id statements that are breaking things for me? The only @Id I see there is fContentId.

cheers,
mg


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 11:37 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Multiple @Id is not supported, you need to use an @IdClass for that

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 10:21 am 
Newbie

Joined: Sun Jun 24, 2007 10:24 am
Posts: 6
Thank you, that seems to get me further :)

But I still cant commit the insert because now I have a new problem:

Code:
java.sql.BatchUpdateException: Incorrect integer value: '’' for column 'fContentId' at row 1


fContentId is just a foreign key, and from the logs I see that Content._id is 53:

Code:
class Content:
   @Column(name="fId")
   @Id @GeneratedValue( strategy=GenerationType.AUTO)
   Long _id= null;
   public void setId( Long id ) { _id= id; }
   public Long getId( ) { return _id; }

@IdClass(ContentItemId.class)
@Entity @Table(name="tContentItem")
class ContentItem:
   @ManyToOne( cascade = { }, fetch=FetchType.LAZY )
   @JoinColumn(name="fContentId")
   @Id
   Content _content= null;
   public void setContent( Content content ) { _content= content; }
   public Content getContent( ) { return _content; }

class ContentItemId:
   @Column(name="fContentId")
   Content _content= null;
   public void setContent( Content content ) { _content= content; }
   public Content getContent( ) { return _content; }


Why is a Long variable returning '’'? Anyone recognize what is going on here?

cheers,
mg


Top
 Profile  
 
 Post subject: I am having this exact same problem
PostPosted: Fri Jul 20, 2007 4:28 am 
Newbie

Joined: Fri Jul 20, 2007 4:25 am
Posts: 1
Hi,

I am having this exact same problem (the "Incorrect integer value" one). Did you ever find a solution?

Cheers,

John.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 11:56 am 
Newbie

Joined: Sun Jun 24, 2007 10:24 am
Posts: 6
Yes

Had to chance

Code:
@Column( name=".." )
@Id
getter/setters


to

Code:
@ManyToOne
@JoinColumn( name="..." )
@Id
getters/setters

on all fields where I was getting the "incorrect integer value" error.

cheers,
mg


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.