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)