[jboss-dev-forums] [Design of EJB 3.0] - Re: EmbeddId and TableGenerator

phil92100 do-not-reply at jboss.com
Sat Feb 17 09:42:14 EST 2007


Some precisions, here is the code for the Embeddable


  | @Embeddable
  | public class ContactId implements Serializable {
  | 	@GeneratedValue(strategy = GenerationType.TABLE, generator = "contact_CODE_Gen")
  | 	@TableGenerator(name = "contact_CODE_Gen", table = "SEQUENCE_BLOCK", pkColumnName = "NAME", valueColumnName = "IDX", pkColumnValue = "contact.CODE", initialValue = 1, allocationSize = 1)
  | 	@Column(insertable = true, updatable = true, name = "CODE")
  | 	private java.lang.Integer code;
  | 
  | 	public ContactId() {
  | 		System.out.println("ContactId - ContactId - constructor : ");
  | 	}
  | 
  | 	public ContactId(java.lang.Integer code) {
  | 		System.out.println("ContactId - ContactId - constructor : " + code);
  | 		this.code = code;
  | 	}
  | 
  | 	public java.lang.Integer getCode() {
  | 		System.out.println("ContactId - getCode - code : " + code);
  | 		return code;
  | 	}
  | 
  | 	public void setCode(java.lang.Integer code) {
  | 		System.out.println("ContactId - setCode - code : " + code);
  | 		this.code = code;
  | 	}
  | 
  | 	public boolean equals(Object o) {
  | 		return ((o instanceof ContactId) && code.equals(((ContactId) o).getCode()));
  | 	}
  | 
  | 	public int hashCode() {
  | 		return code.hashCode();
  | 	}
  | }
  | 

and the entity

  | @Entity(name = "ejb30/Contact")
  | @EntityListeners( { ContactListener.class })
  | @Table(name = "contact")
  | public class Contact implements Serializable {
  | 	static final long serialVersionUID = 1171222220859l;
  | 
  | 	@EmbeddedId
  | 	protected ContactId id;
  | 
  | 	@Basic(optional = false, fetch = FetchType.EAGER)
  | 	@Column(insertable = true, updatable = true, name = "LIBELLE")
  | 	private java.lang.String libelle;
  | 
  | 	public Contact() {
  | 		this.id = new ContactId();
  | 	}
  | 
  | 	public Contact(java.lang.Integer code) {
  | 		this.id = new ContactId(code);
  | 	}
  | 
  | 	public ContactId getId() {
  | 		return id;
  | 	}
  | 
  | 	public void setId(ContactId id) {
  | 		this.id = id;
  | 	}
  | 
  | 	public java.lang.String getLibelle() {
  | 		return libelle;
  | 	}
  | 
  | 	public void setLibelle(java.lang.String libelle) {
  | 		this.libelle = libelle;
  | 	}
  | }
  | 

And the JBoss 4.0.5 exception :

  | 15:32:19,156 WARN  [JDBCExceptionReporter] SQL Error: 1048, SQLState: 23000
  | 15:32:19,156 ERROR [JDBCExceptionReporter] Column 'CODE' cannot be null
  | 15:32:19,156 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
  | org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
  |         at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
  |         at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
  |         at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
  |         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)
  |         at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
  |         at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
  |         at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1491)
  |         at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1110)
  |         at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:324)
  |         at org.jboss.tm.TxManager.commit(TxManager.java:240)
  |         at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
  |         at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
  |         at org.jboss.aspects.tx.TxInterceptor$RequiresNew.invoke(TxInterceptor.java:262)
  |         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  |         at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
  |         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  |         at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
  |         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  |         at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
  |         at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
  |         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  |         at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
  |         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  |         at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
  |         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  |         at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:263)
  |         at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
  |         at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
  |         at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
  |         at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
  |         at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
  |         at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:398)
  |         at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
  | Caused by: java.sql.BatchUpdateException: Column 'CODE' cannot be null
  |         at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:828)
  |         at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:519)
  |         at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
  |         at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
  |         ... 34 more
  | 

Thanks for your help.
Philippe

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4018175#4018175

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4018175



More information about the jboss-dev-forums mailing list