0

I have been battling with this for the last few days and am at the end of my tether. Please can someone help me figure out where/why I am going wrong. Thank you very much indeed.

Here is my story: I am building a web EE application using JBOSS 6.10, and Potgres9.1. Ultimately, I will be using JSF for views but for now I am using a simple Servlet (com.shop.cart.ShoppingCartClient.java) to test the database connectivity and I am injecting a CustomerManager sateless session bean to the servlet and this session bean has a method that executes EntityManager,persist() to store a newly created Customer entity. The application is called HawelyPlaceshop- the war file deploys ok and when I invoke the Servlet on the browser (Chrome), I get the following error in the jBOSS console:

Latest Error:

12:09:24,768 WARN  [org.hibernate.util.JDBCExceptionReporter] SQL Error: 0, SQLState: 23502
12:09:24,768 ERROR [org.hibernate.util.JDBCExceptionReporter] ERROR: null value in column "customerid" violates not-null constraint
  Detail: Failing row contains (null, null, null, null).
12:09:24,785 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/HawleyPlaceShop].[/ShoppingCartClient]] Servlet.service() for servlet /ShoppingCartClient threw exception: javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not insert: [com.shop.entity.Customer]
    at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:183) [:0.0.2]
    at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:251) [:0.0.2]
    at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.required(CMTTxInterceptor.java:349) [:0.0.2]
    at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.invoke(CMTTxInterceptor.java:209) [:0.0.2]
    at org.jboss.ejb3.tx2.aop.CMTTxInterceptorWrapper.invoke(CMTTxInterceptorWrapper.java:52) [:0.0.2]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76) [:1.0.0.GA]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42) [:1.0.4]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:182) [:1.7.21]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41) [:1.7.21]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67) [:1.7.21]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.core.context.CurrentInvocationContextInterceptor.invoke(CurrentInvocationContextInterceptor.java:47) [:1.7.21]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67) [:1.0.1]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.interceptor.EJB3TCCLInterceptor.invoke(EJB3TCCLInterceptor.java:86) [:1.7.21]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:333) [:1.7.21]
    at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:390) [:1.7.21]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.7.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [:1.7.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.7.0_65]
    at java.lang.reflect.Method.invoke(Unknown Source) [:1.7.0_65]
    at org.jboss.ejb3.proxy.impl.handler.session.SessionLocalProxyInvocationHandler$LocalContainerInvocation.invokeTarget(SessionLocalProxyInvocationHandler.java:184) [:1.0.11]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.async.impl.interceptor.AsynchronousClientInterceptor.invoke(AsynchronousClientInterceptor.java:143) [:1.7.21]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.proxy.impl.handler.session.SessionLocalProxyInvocationHandler$LocalInvokableContextHandler.invoke(SessionLocalProxyInvocationHandler.java:159) [:1.0.11]
    at com.sun.proxy.$Proxy166.invoke(Unknown Source)
    at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:185) [:1.0.11]
    at com.sun.proxy.$Proxy189.persistNewCustomer(Unknown Source)
    at com.shop.cart.ShoppingCartClient.processRequest(ShoppingCartClient.java:41) [:]
    at com.shop.cart.ShoppingCartClient.doGet(ShoppingCartClient.java:77) [:]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [:1.0.0.Final]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.1.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
    at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67) [:6.1.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0.Final]
    at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
    at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0.Final]
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
    at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
    at java.lang.Thread.run(Unknown Source) [:1.7.0_65]
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not insert: [com.shop.entity.Customer]
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1215) [:3.6.6.Final]
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1148) [:3.6.6.Final]
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1154) [:3.6.6.Final]
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:678) [:3.6.6.Final]
    at org.jboss.jpa.impl.tx.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:206) [:2.0.0]
    at com.shop.entity.CustomerManagerBean.persistNewCustomer(CustomerManagerBean.java:58) [:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.7.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [:1.7.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.7.0_65]
    at java.lang.reflect.Method.invoke(Unknown Source) [:1.7.0_65]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.interceptors.container.ContainerMethodInvocationWrapper.invokeNext(ContainerMethodInvocationWrapper.java:72) [:1.1.3]
    at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor$InvocationContext.proceed(InvocationContextInterceptor.java:127) [:1.1.3]
    at org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:151) [:6.1.0.Final]
    at org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor.doAroundInvoke(Jsr299BindingsInterceptor.java:122) [:6.1.0.Final]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.7.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [:1.7.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.7.0_65]
    at java.lang.reflect.Method.invoke(Unknown Source) [:1.7.0_65]
    at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:80) [:1.1.3]
    at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:71) [:1.1.3]
    at org.jboss.ejb3.interceptors.container.ContainerMethodInvocationWrapper.invokeNext(ContainerMethodInvocationWrapper.java:62) [:1.1.3]
    at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor$InvocationContext.proceed(InvocationContextInterceptor.java:127) [:1.1.3]
    at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:46) [:6.1.0.Final]
    at org.jboss.weld.integration.deployer.metadata.WeldLifecycleInterceptor.doAroundInvoke(WeldLifecycleInterceptor.java:55) [:6.1.0.Final]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.7.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [:1.7.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.7.0_65]
    at java.lang.reflect.Method.invoke(Unknown Source) [:1.7.0_65]
    at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:80) [:1.1.3]
    at org.jboss.ejb3.interceptors.aop.EJB3InterceptorInterceptor.invoke(EJB3InterceptorInterceptor.java:71) [:1.1.3]
    at org.jboss.ejb3.interceptors.container.ContainerMethodInvocationWrapper.invokeNext(ContainerMethodInvocationWrapper.java:62) [:1.1.3]
    at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:76) [:1.1.3]
    at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:62) [:1.1.3]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.7.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [:1.7.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [:1.7.0_65]
    at java.lang.reflect.Method.invoke(Unknown Source) [:1.7.0_65]
    at org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:74) [:1.1.3]
    at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_1281133.invoke(InvocationContextInterceptor_z_fillMethod_1281133.java) [:]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:90) [:1.1.3]
    at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_1281133.invoke(InvocationContextInterceptor_z_setup_1281133.java) [:]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.async.impl.interceptor.AsynchronousServerInterceptor.invoke(AsynchronousServerInterceptor.java:128) [:1.7.21]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62) [:1.7.21]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56) [:1.7.21]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) [:1.7.21]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42) [:1.0.4]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68) [:1.7.21]
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.2.GA]
    at org.jboss.ejb3.core.context.SessionInvocationContextAdapter.proceed(SessionInvocationContextAdapter.java:95) [:1.7.21]
    at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:247) [:0.0.2]
    ... 60 more
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [com.shop.entity.Customer]
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96) [:3.6.6.Final]
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) [:3.6.6.Final]
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64) [:3.6.6.Final]
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2345) [:3.6.6.Final]
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2852) [:3.6.6.Final]
    at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71) [:3.6.6.Final]
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273) [:3.6.6.Final]
    at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:320) [:3.6.6.Final]
    at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203) [:3.6.6.Final]
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129) [:3.6.6.Final]
    at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69) [:3.6.6.Final]
    at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179) [:3.6.6.Final]
    at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135) [:3.6.6.Final]
    at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61) [:3.6.6.Final]
    at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808) [:3.6.6.Final]
    at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782) [:3.6.6.Final]
    at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786) [:3.6.6.Final]
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672) [:3.6.6.Final]
    ... 117 more
Caused by: org.postgresql.util.PSQLException: ERROR: null value in column "customerid" violates not-null constraint
  Detail: Failing row contains (null, null, null, null).
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198) [:]
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927) [:]
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) [:]
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:561) [:]
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:419) [:]
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:365) [:]
    at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:365) [:6.1.0.Final]
    at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94) [:3.6.6.Final]
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57) [:3.6.6.Final]
    ... 132 more

Customer Entity bean

package com.shop.entity;
import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SecondaryTable;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * @author Lalin
 *
 */
@Entity(name="Customer")
@Table(name="Customer")
@SecondaryTable(name="Customer")


public class Customer implements Serializable {

    //public Customer(){} // non arg constructor - can have others

    @Id
    @Column (name = "CustomerId", nullable = false, insertable = true)

    @GeneratedValue(strategy = GenerationType.IDENTITY)

    private Integer CustomerId;
    @Basic(fetch=FetchType.EAGER)
    @Column(name="Name", table="Customer")
    private String Name;
    @Basic(fetch=FetchType.EAGER)
    @Column(name="Telephone", table="Customer")
    private String Telephone;
    @Basic(fetch=FetchType.EAGER)
    @Column(name="MobilePhone", table="Customer")
    private String MobilePhone;
    private static final long serialVersionUID = 1L;

    public Integer getCustomerId() {
        return CustomerId;
    }

    public void setCustomerId(Integer customerId) {
        this.CustomerId= customerId;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        this.Name = name;
    }

    public String getTelephone() {
        return Telephone;
    }

    public void setTelephone(String telephone) {
        this.Telephone = telephone;
    }

    public String getMobilePhone() {
        return MobilePhone;
    }

    public void setMobilePhone(String mobilePhone) {
        this.MobilePhone = mobilePhone;
    }


}
  • It seems that your EntityManager is null. Are there any other errors in application startup that you did not mention? Also, could you please try to debug this method and see what's going on? – Magic Wand Jul 29 '14 at 07:28
  • Entity Manager issue is fixed thabks to you @Miljenko. Now its complaning about the connection to the database. Please see above for the console info – Lalin Pethiyagoda Jul 29 '14 at 10:46
  • This one is easy: you are missing PostgreSQL JDBC driver in classpath. Get JDBC driver (http://jdbc.postgresql.org/download.html), and copy it into application servers lib directory (e.g. standalone/deployments). More about it and DataSource creation can be found on https://community.jboss.org/wiki/DataSourceConfigurationInAS7 – Magic Wand Jul 29 '14 at 11:02

2 Answers2

0

You have @Entity annotation on your persistent class, but it does not define table properties:

@Entity
@Table(name="CUSTOMER")
public class Customer implements Serializable {
  // ...
}

or whatever table name is.

Magic Wand
  • 1,572
  • 10
  • 9
  • Hi Miljenko, Thanks for the reply. I thought the @Table annotation set the corresponding table name in the database? – Lalin Pethiyagoda Jul 28 '14 at 10:36
  • Thanks for the reply. I thought the Table annotation set the corresponding table name in the database? Also, do I have to explicitly use the Column annotation on all the fields in the persistent class? – Lalin Pethiyagoda Jul 28 '14 at 10:40
  • If you do not define Table annotation, JPA uses class name as table name. The same is with fields: if field does not have Column definition, then JPA uses field name as column name. These annotations use exclusively to customize JPA entities to database properties. – Magic Wand Jul 28 '14 at 11:04
  • Do you have table CUSTOMER defined in your database? Does user "postgres" you are using to connect to database sees this table? Try to remove hibernate properties "hibernate.dialect" (it is used twice), "hibernate.connection.username" and "hibernate.connection.password" (they are already defined on DataSource level). Or maybe remove all hibernate-specific properties from persistence.xml as your setup is creating tables on startup. – Magic Wand Jul 28 '14 at 11:11
  • Also, property "hibernate.hbm2ddl.auto" is invalid. Valid values are validate | update | create | create-drop – Magic Wand Jul 28 '14 at 11:16
  • Do you have table CUSTOMER defined in your database?-Yes it is – Lalin Pethiyagoda Jul 28 '14 at 11:32
  • Does user "postgres" you are using to connect to database sees this table?-I don't know how to check this – Lalin Pethiyagoda Jul 28 '14 at 11:33
  • Use your favorite DB tool (DBeaver, DBVisualizer, SquirrelSQL or pgAdmin) to connect as user postgres. Also, please attach whole stack trace from application. – Magic Wand Jul 28 '14 at 11:42
  • Hi, I tried everythng you said above, and in fact deleted the customer table from the database to see if it makes a difference. Have added column annotations to all the fields in thhe entity class, removed the username and password entries and any duplicate entries from persistence.xml, to no avail...... – Lalin Pethiyagoda Jul 28 '14 at 16:38
  • Dear Miljenko, I have tried everything and here is the current status. JBOSS does not recognise the dependency injection of EntityManager in my bean class that acts as a facade to the servelt. The bean class is is called CustomerManagerBean and is a stateless bean. There I inject EntityManager and have a void method that accepts an object which is then used in entitymanager.persist(). I create an instance of the facade bean inside the servelt and then call the persistCustomer() method, and it bobs out! please help! – Lalin Pethiyagoda Jul 31 '14 at 06:55
  • OK, so CustomerManagerBean is correctly injected into Servlet (it is not null)? I wonder how CustomerManagerLocal looks like, because CustomerManagerBean implements CustomerManagerLocal. Is CustomerManagerLocal annotated with @Local annotation? Can you try to remove "implements CustomerManagerLocal" from CustomerManagerBean? Are there any other errors in application startup you did not mention? – Magic Wand Jul 31 '14 at 08:10
  • fixed it using a setter method for the bean here is the link for that http://stackoverflow.com/questions/5387022/how-to-get-container-managed-transactions-cmt-working-with-ejb-3-1-hibernate?rq=1 – Lalin Pethiyagoda Jul 31 '14 at 09:54
  • now it comlains that the primary key is duplicated: even when I use unique numbers .... – Lalin Pethiyagoda Jul 31 '14 at 09:55
  • Please post Customer entity source code and error you are getting, it's hard to tell anything without the code. – Magic Wand Jul 31 '14 at 10:04
  • Did you define field CustomerId in PostgreSQL database as an IDENTITY column (see http://stackoverflow.com/questions/7718585/set-auto-increment-primary-key-in-postgresql)? – Magic Wand Jul 31 '14 at 14:49
  • Yeah, I did, its CREATE TABLE customer ( customerid SERIAL UNIQUE, mobilephone character varying(255), name character varying(255), telephone character varying(255) ) WITH ( OIDS=FALSE ); ALTER TABLE customer OWNER TO postgres; – Lalin Pethiyagoda Aug 02 '14 at 06:41
  • Its working!!!! It appears that when using JPA you have to use different names for the POJO (with the Entity annotation) and the table in the database. Initially I named them both the same (Customer) It works beautifully when I changed names (POJO:CustomerEntity, Postgres table: customer). I am still using the sequence and I have t the primary key datatype as SERIAL. THANK YOU SO MUCH!! for your help.... – Lalin Pethiyagoda Aug 05 '14 at 11:43
0

Its working!!!! It appears that when using JPA you have to use different names for the POJO (with the Entity annotation) and the table in the database. Initially I named them both the same (Customer) It works beautifully when I changed names (POJO:CustomerEntity, Postgres table: customer). I am still using the sequence and I have t the primary key datatype as SERIAL.