Hello everyone,
I have a problem while trying to insert an user to my db.
Here is my User.java:
Code:
...
private int id = 0;
private String login = null;
private String password = null;
private Date creationDate = new Date();
private int idActivationState = 0;
private Profile profile = null;
private UserCategory userCategory = null;
private List<UserResource> resourceList = null;
private List<Article> articleList = null;
private List<Comment> commentList = null;
private Rating rating = null;
...
My user.hbm:
Code:
<hibernate-mapping package="com.elnominal.model.user" auto-import="false">
<class name="User" table="elnominal_user" lazy="true">
<id name="id" type="integer" column="id">
<generator class="sequence">
<param name="sequence">elnominal_user_id_seq</param>
</generator>
</id>
<property name="login" type="string" column="login" length="50" not-null="true" unique="true"/>
<property name="password" type="string" column="password" length="50" not-null="true"/>
<property name="creationDate" column="creation_date" type="java.util.Date" update="false" not-null="true"/>
<property name="idActivationState" type="integer" column="id_activation_state" not-null="true"/>
<many-to-one name="profile" cascade="all" class="com.elnominal.model.user.Profile" column="id_profile" not-null="true"/>
<many-to-one name="rating" cascade="all" class="com.elnominal.model.rating.Rating" column="id_rating" not-null="true"/>
<many-to-one name="userCategory" cascade="none" class="com.elnominal.model.category.UserCategory" column="id_category" not-null="true"/>
<bag name="resourceList" cascade="all" inverse="true">
<key column="id_user"/>
<one-to-many class="com.elnominal.model.resource.UserResource"/>
</bag>
<bag name="articleList" cascade="all" inverse="true">
<key column="id_user"/>
<one-to-many class="com.elnominal.model.article.Article"/>
</bag>
<bag name="commentList" cascade="all" inverse="true">
<key column="id_user"/>
<one-to-many class="com.elnominal.model.comment.Comment"/>
</bag>
</class>
</hibernate-mapping>
My Resource.java (UserResource extends from it):
Code:
...
private int id = 0;
private String title = null;
private String description = null;
private String fileName;
private String filePath;
private Date creationDate = new Date();
private ResourceCategory resourceCategory = null;
...
And my Resource.hbm:
Code:
<hibernate-mapping package="com.elnominal.model.resource">
<class name="Resource" lazy="true">
<id name="id" type="integer" column="id">
<generator class="sequence"/>
</id>
<property name="title" type="string" column="title" length="100" not-null="true"/>
<property name="description" type="string" column="description" length="1000" not-null="false"/>
<property name="fileName" type="string" column="file_name" length="100" not-null="true"/>
<property name="filePath" type="string" column="file_path" length="200" not-null="true"/>
<property name="creationDate" column="creation_date" type="java.util.Date" update="false" not-null="true"/>
<many-to-one name="resourceCategory" cascade="none" class="com.elnominal.model.category.ResourceCategory" column="id_category" not-null="true"/>
<union-subclass name="ArticleResource" table="elnominal_article_resource" />
<union-subclass name="UserResource" table="elnominal_user_resource" />
</class>
</hibernate-mapping>
And finally the exception i am getting everytime i try to insert an user:
Code:
GRAVE: ERROR: null value in column "id_user" violates not-null constraint
22-mar-2009 18:10:18 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
GRAVE: 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:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
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.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.elnominal.persistence.HibernateUtil.commitTransaction(HibernateUtil.java:165)
at com.elnominal.dao.UserDAO.makePersistent(UserDAO.java:171)
at com.elnominal.servlet.controller.InsertUserServlet.service(InsertUserServlet.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.elnominal.servlet.SearchDataFilter.doFilter(SearchDataFilter.java:44)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.elnominal.servlet.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:104)
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:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into elnominal_user_resource (title, description, file_name, file_path, creation_date, id_category, id) values (asdas, NULL, portada.jpg, D:/trabajo/proyectos/elnominal/web/upload/portada.jpg, 2009-03-22 18:10:16.671000 +01:00:00, 1, 58) was aborted. Call getNextException to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2537)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1328)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:351)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2674)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 29 more
22-mar-2009 18:10:18 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() para servlet InsertUserServlet lanz� excepci�n
com.elnominal.exception.InfrastructureException: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at com.elnominal.persistence.HibernateUtil.commitTransaction(HibernateUtil.java:170)
at com.elnominal.dao.UserDAO.makePersistent(UserDAO.java:171)
at com.elnominal.servlet.controller.InsertUserServlet.service(InsertUserServlet.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.elnominal.servlet.SearchDataFilter.doFilter(SearchDataFilter.java:44)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.elnominal.servlet.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:104)
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:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: 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:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
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.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.elnominal.persistence.HibernateUtil.commitTransaction(HibernateUtil.java:165)
... 21 more
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into elnominal_user_resource (title, description, file_name, file_path, creation_date, id_category, id) values (asdas, NULL, portada.jpg, D:/trabajo/proyectos/elnominal/web/upload/portada.jpg, 2009-03-22 18:10:16.671000 +01:00:00, 1, 58) was aborted. Call getNextException to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2537)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1328)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:351)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2674)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 29 more
Can someone help me? i am stuck at this...
Thanks in advance