Hibernate version:3
Mapping documents:
/** * PrWorksheet generated by hbm2java */ @Entity @Table(name = "pr_worksheet", catalog = "timereporting") public class PrWorksheet implements java.io.Serializable { private static final long serialVersionUID = 5540290338546120309L; private Integer seqno; private PrProject prProject; private PrLocation prLocation; private PrStaff prStaffByStatusModifier; private PrWorkunit prWorkunit; private PrProjectTask prProjectTask; private PrStaff prStaffByStaffNo; private Date reportDate; private BigDecimal effort; private BigDecimal overtime; private String status; private Date statusModified;
public PrWorksheet() { }
public PrWorksheet(PrProject prProject, PrLocation prLocation, PrWorkunit prWorkunit, PrProjectTask prProjectTask, PrStaff prStaffByStaffNo, Date reportDate, BigDecimal effort) { this.prProject = prProject; this.prLocation = prLocation; this.prWorkunit = prWorkunit; this.prProjectTask = prProjectTask; this.prStaffByStaffNo = prStaffByStaffNo; this.reportDate = reportDate; this.effort = effort; }
public PrWorksheet(PrProject prProject, PrLocation prLocation, PrStaff prStaffByStatusModifier, PrWorkunit prWorkunit, PrProjectTask prProjectTask, PrStaff prStaffByStaffNo, Date reportDate, BigDecimal effort, BigDecimal overtime, String status, Date statusModified) { this.prProject = prProject; this.prLocation = prLocation; this.prStaffByStatusModifier = prStaffByStatusModifier; this.prWorkunit = prWorkunit; this.prProjectTask = prProjectTask; this.prStaffByStaffNo = prStaffByStaffNo; this.reportDate = reportDate; this.effort = effort; this.overtime = overtime; this.status = status; this.statusModified = statusModified; }
@Id @GeneratedValue(strategy = IDENTITY) @Column(name = "SEQNO", unique = true, nullable = false) public Integer getSeqno() { return this.seqno; }
public void setSeqno(Integer seqno) { this.seqno = seqno; }
@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "PROJ_CODE", nullable = false) public PrProject getPrProject() { return this.prProject; }
public void setPrProject(PrProject prProject) { this.prProject = prProject; }
@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "LOC_CODE", nullable = false) public PrLocation getPrLocation() { return this.prLocation; }
public void setPrLocation(PrLocation prLocation) { this.prLocation = prLocation; }
@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "STATUS_MODIFIER") public PrStaff getPrStaffByStatusModifier() { return this.prStaffByStatusModifier; }
public void setPrStaffByStatusModifier(PrStaff prStaffByStatusModifier) { this.prStaffByStatusModifier = prStaffByStatusModifier; }
@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "WORK_UNIT", nullable = false) public PrWorkunit getPrWorkunit() { return this.prWorkunit; }
public void setPrWorkunit(PrWorkunit prWorkunit) { this.prWorkunit = prWorkunit; }
@ManyToOne(fetch = FetchType.LAZY) @JoinColumns( { @JoinColumn(name = "PROJ_CODE", referencedColumnName = "PROJ_CODE", nullable = false, insertable = false, updatable = false), @JoinColumn(name = "PRTASK_CODE", referencedColumnName = "PRTASK_CODE", nullable = false, insertable = false, updatable = false) }) public PrProjectTask getPrProjectTask() { return this.prProjectTask; }
public void setPrProjectTask(PrProjectTask prProjectTask) { this.prProjectTask = prProjectTask; }
@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "STAFF_NO", nullable = false) public PrStaff getPrStaffByStaffNo() { return this.prStaffByStaffNo; }
public void setPrStaffByStaffNo(PrStaff prStaffByStaffNo) { this.prStaffByStaffNo = prStaffByStaffNo; }
@Temporal(TemporalType.TIMESTAMP) @Column(name = "REPORT_DATE", nullable = false, length = 19) public Date getReportDate() { return this.reportDate; }
public void setReportDate(Date reportDate) { this.reportDate = reportDate; }
@Column(name = "EFFORT", nullable = false, precision = 10) public BigDecimal getEffort() { return this.effort; }
public void setEffort(BigDecimal effort) { this.effort = effort; }
@Column(name = "OVERTIME", precision = 10) public BigDecimal getOvertime() { return this.overtime; }
public void setOvertime(BigDecimal overtime) { this.overtime = overtime; }
@Column(name = "STATUS", length = 1) public String getStatus() { return this.status; }
public void setStatus(String status) { this.status = status; }
@Temporal(TemporalType.TIMESTAMP) @Column(name = "STATUS_MODIFIED", length = 19) public Date getStatusModified() { return this.statusModified; }
public void setStatusModified(Date statusModified) { this.statusModified = statusModified; }
}
/** * PrProjectTask generated by hbm2java */ @Entity @Table(name = "pr_project_task", catalog = "timereporting") public class PrProjectTask implements java.io.Serializable { private static final long serialVersionUID = 7946332587725218980L; private PrProjectTaskId id; private PrProject prProject; private String taskName; private String taskType; private String mandatoryWu; private String preferredLocation; private String notvisible; private Set<PrDcr> prDcrs = new HashSet<PrDcr>(0); private Set<PrWorksheet> prWorksheets = new HashSet<PrWorksheet>(0); private Set<PrProjectRole> prProjectRoles = new HashSet<PrProjectRole>(0);
public PrProjectTask() { }
public PrProjectTask(PrProjectTaskId id, PrProject prProject, String taskName, String taskType, String preferredLocation) { this.id = id; this.prProject = prProject; this.taskName = taskName; this.taskType = taskType; this.preferredLocation = preferredLocation; }
public PrProjectTask(PrProjectTaskId id, PrProject prProject, String taskName, String taskType, String mandatoryWu, String preferredLocation, String notvisible, Set<PrDcr> prDcrs, Set<PrWorksheet> prWorksheets, Set<PrProjectRole> prProjectRoles) { this.id = id; this.prProject = prProject; this.taskName = taskName; this.taskType = taskType; this.mandatoryWu = mandatoryWu; this.preferredLocation = preferredLocation; this.notvisible = notvisible; this.prDcrs = prDcrs; this.prWorksheets = prWorksheets; this.prProjectRoles = prProjectRoles; }
@EmbeddedId @AttributeOverrides( { @AttributeOverride(name = "projCode", column = @Column(name = "PROJ_CODE", nullable = false, length = 80)), @AttributeOverride(name = "prtaskCode", column = @Column(name = "PRTASK_CODE", nullable = false, length = 80)) }) public PrProjectTaskId getId() { return this.id; }
public void setId(PrProjectTaskId id) { this.id = id; }
@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "PROJ_CODE", nullable = false, insertable = false, updatable = false) public PrProject getPrProject() { return this.prProject; }
public void setPrProject(PrProject prProject) { this.prProject = prProject; }
@Column(name = "TASK_NAME", nullable = false, length = 100) public String getTaskName() { return this.taskName; }
public void setTaskName(String taskName) { this.taskName = taskName; }
@Column(name = "TASK_TYPE", nullable = false, length = 45) public String getTaskType() { return this.taskType; }
public void setTaskType(String taskType) { this.taskType = taskType; }
@Column(name = "MANDATORY_WU", length = 10) public String getMandatoryWu() { return this.mandatoryWu; }
public void setMandatoryWu(String mandatoryWu) { this.mandatoryWu = mandatoryWu; }
@Column(name = "PREFERRED_LOCATION", nullable = false, length = 80) public String getPreferredLocation() { return this.preferredLocation; }
public void setPreferredLocation(String preferredLocation) { this.preferredLocation = preferredLocation; }
@Column(name = "NOTVISIBLE", length = 10) public String getNotvisible() { return this.notvisible; }
public void setNotvisible(String notvisible) { this.notvisible = notvisible; }
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "prProjectTask") public Set<PrDcr> getPrDcrs() { return this.prDcrs; }
public void setPrDcrs(Set<PrDcr> prDcrs) { this.prDcrs = prDcrs; }
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "prProjectTask") public Set<PrWorksheet> getPrWorksheets() { return this.prWorksheets; }
public void setPrWorksheets(Set<PrWorksheet> prWorksheets) { this.prWorksheets = prWorksheets; }
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "prProjectTask") public Set<PrProjectRole> getPrProjectRoles() { return this.prProjectRoles; }
public void setPrProjectRoles(Set<PrProjectRole> prProjectRoles) { this.prProjectRoles = prProjectRoles; }
}
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
16:14:08,175 ERROR [STDERR] 97109 [http-127.0.0.1-8080-2] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 1364, SQLState: HY000 16:14:08,175 ERROR [STDERR] 97109 [http-127.0.0.1-8080-2] ERROR org.hibernate.util.JDBCExceptionReporter - Field 'PRTASK_CODE' doesn't have a default value 16:14:08,175 ERROR [PrWorksheetHome] persist failed javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not insert: [com.atosorigin.utils.pojo.PrWorksheet] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637) at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:226) at org.jboss.ejb3.entity.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:182) at com.atosorigin.utils.pojo.PrWorksheetHome.persist(PrWorksheetHome.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112) at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166) at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79) at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95) 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:110) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46) 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.localInvoke(StatelessContainer.java:240) at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210) at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84) at $Proxy136.persist(Unknown Source) at com.atosorigin.utils.bean.PrWorksheetBean.insertPrWorksheet(PrWorksheetBean.java:104) at com.atosorigin.timereport.servlet.MainController.doInsertWorksheet(MainController.java:830) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.atosorigin.timereport.servlet.MainController.service(MainController.java:153) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446) at java.lang.Thread.run(Thread.java:595) Caused by: org.hibernate.exception.GenericJDBCException: could not insert: [com.atosorigin.utils.pojo.PrWorksheet] 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.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2163) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2643) at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279) at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298) at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181) at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107) at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49) at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131) at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87) at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38) at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:622) at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596) at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:600) at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220) ... 58 more Caused by: java.sql.SQLException: Field 'PRTASK_CODE' doesn't have a default value at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922) at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:251) at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:72) at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33) ... 73 more
Name and version of the database you are using:Mysql 5.1.12-beta-community-nt via TCP/IP
The generated SQL (show_sql=true): Hibernate: insert into timereporting.pr_worksheet (EFFORT, OVERTIME, LOC_CODE, PROJ_CODE, STAFF_NO, STATUS_MODIFIER, WORK_UNIT, REPORT_DATE, STATUS, STATUS_MODIFIED) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
I am using like this;
prWorksheet.setPrProjectTask(new PrProjectTask());
prWorksheet.getPrProjectTask().setId(new PrProjectTaskId());
prWorksheet.getPrProjectTask().getId().setProjCode(request.getParameter("proj_code"));
prWorksheet.getPrProjectTask().getId().setPrtaskCode(request.getParameter("prtask_code"));
I have tried also this;
prWorksheet.setPrProjectTask(prProjectTaskInstance.findById(new PrProjectTaskId(request.getParameter("proj_code"),request.getParameter("prtask_code"))));
Please help me :(
|