openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John_canada <john_...@canada.com>
Subject Re: did pass params - Attempt to insert null into a non-nullable column
Date Wed, 01 Jul 2009 21:19:10 GMT

Thanks for the quick reply, Rick.

Eventually I found out it was about the datasource config:

in such case(using Tomcat), the
my.war/WEB-INF/classes/META-INF/persistence.xml 
1. should not specify any database info but the datasource id (specified in
/tomcat/conf/openejb.xml), as
	<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
	<jta-data-source>contextDS</jta-data-source>

if specifying the database info, like
<property name="openjpa.ConnectionURL"
                value="jdbc:mysql://localhost:3306/ejb"/>
            <property name="openjpa.ConnectionDriverName"
          ...
then the following error found:

<openjpa-1.2.1-r752877:753278 fatal user error>
org.apache.openjpa.persistence.ArgumentException: A connection could not be
obtained for driver class "com.mysql.jdbc.Driver" and URL
"jdbc:mysql://localhost:3306/ejb".  You may have specified an invalid URL.

org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:256)

org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:242)

org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:692)

org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDataSource(JDBCConfigurationImpl.java:790)

org.apache.openjpa.jdbc.kernel.JDBCStoreManager.setContext(JDBCStoreManager.java:136)

org.apache.openjpa.jdbc.kernel.JDBCStoreManager.setContext(JDBCStoreManager.java:120)

org.apache.openjpa.kernel.DelegatingStoreManager.setContext(DelegatingStoreManager.java:78)
	org.apache.openjpa.kernel.BrokerImpl.initialize(BrokerImpl.java:309)

org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:216)

org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:190)

org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)

org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)

org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)

org.apache.openejb.persistence.JtaEntityManagerRegistry.getEntityManager(JtaEntityManagerRegistry.java:105)

org.apache.openejb.persistence.JtaEntityManager.getEntityManager(JtaEntityManager.java:61)

org.apache.openejb.persistence.JtaEntityManager.persist(JtaEntityManager.java:97)
...

2. create and place up openejb.xml and open-ejb-jar.xml in the same
METTA-INF folder, companied with persistence.xml, then the created entity
bean and its data can be found/accessed in run time (in debug), but it's not
persisted in database.

openejb-jar.xml
    <dep:environment>
        <dep:moduleId>
            <dep:groupId>myEJB</dep:groupId>
            <dep:artifactId>EJB</dep:artifactId>
            <dep:version>2.0</dep:version>
            <dep:type>car</dep:type>
        </dep:moduleId>
    </dep:environment>
    <name:cmp-connection-factory>
        <name:pattern>
            <name:groupId>console.myTX</name:groupId>
            <name:artifactId>myTX</name:artifactId>
        </name:pattern>
    </name:cmp-connection-factory>

data info in openejb.xml as:
        <Resource id="myTX" type="DataSource">
                JdbcDriver com.mysql.jdbc.Driver
                ...
        </Resource>        
        <Resource id="myNOTX" type="DataSource">
                JdbcDriver com.mysql.jdbc.Driver
                ....
        </Resource>

the persistence.xml:
<persistence-unit name="aUnit" > 
	<jta-data-source>myTX</jta-data-source>
	<non-jta-data-source>myNOTX</non-jta-data-source>
...

so, my question became, how to specify the datasource out of /tomcat/conf/?

Thanks in advance.

--
John
 



Rick Curtis wrote:
> 
> John -
> 
> It looks like you annotated your Person.id to be unique, but you didn't
> specify a value... I'm assuming that you're using an AI column for your
> id.
> I see you're running on MySQL, so try adding the annotation
> @GeneratedValue(strategy=GenerationType.IDENTITY) to your id column. If
> that
> doesn't work, please post a snippet of your Entity/mapping file(s).
> 
> -Rick
> 
> On Wed, Jul 1, 2009 at 12:44 PM, John_canada <john_woo@canada.com> wrote:
> 
>>
>> Hi,
>>
>> I deployed openejb.war in tomcat, and tested a web app which used ejb3;
>> it's
>> very simple: a servlet called a stateless bean, which created an entity
>> as
>> following:
>>
>> session bean:
>> @PersistenceContext(unitName="aUnit",type =
>> PersistenceContextType.TRANSACTION)
>> private EntityManager manager;
>>
>> Person p = new Person(name, address);
>> manager.persist(p);
>> manager.flush();
>>
>> the persistence.xml:
>> <persistence-unit name="aUnit" transaction-type="JTA">
>>
>> 
>> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>>        <jta-data-source>myTX</jta-data-source>
>>        <non-jta-data-source>myNOTX</non-jta-data-source>
>>        <class>ejb.Person</class>
>>  ...
>>
>> openejb.xml:
>>        <Resource id="myTX" type="DataSource">
>>                JdbcDriver com.mysql.jdbc.Driver
>>                JdbcUrl jdbc:mysql://localhost:3306/a
>>                UserName root
>>                Password aaa
>>        </Resource>
>>
>>        <Resource id="myNOTX" type="DataSource">
>>                JdbcDriver com.mysql.jdbc.Driver
>>                JdbcUrl jdbc:mysql://localhost:3306/a
>>                UserName root
>>                Password aaa
>>                JtaManaged false
>>        </Resource>
>>
>> However, I got the following error when executing manager.flush();
>> org.apache.openjpa.lib.jdbc.ReportingSQLException: Attempt to insert null
>> into a non-nullable column: column: ID table: PERSON in statement [INSERT
>> INTO person (person_id, address, name) VALUES (?, ?, ?)] {prepstmnt
>> 6240623
>> INSERT INTO person (person_id, address, name)
>>    VALUES (?, ?, ?)
>> [params=(long) 2201, (String) any address, (String) name]} [code=-10,
>> state=23000]
>>
>>
>> org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:192)
>>
>>
>> org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$700(LoggingConnectionDecorator.java:57)
>>
>>
>> org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:866)
>>
>>
>> org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:269)
>>
>>
>> org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1504)
>>
>>
>> org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.executeUpdate(PreparedStatementManagerImpl.java:151)
>>
>>
>> org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:120)
>>
>>
>> org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushAndUpdate(BatchingPreparedStatementManagerImpl.java:82)
>>
>>
>> org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:89)
>>
>>
>> org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:72)
>>
>>
>> org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:543)
>>
>>
>> org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:105)
>>
>>
>> org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:59)
>>
>>
>> org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:89)
>>
>>
>> org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72)
>>
>>
>> org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:655)
>>
>>
>> org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
>>        org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2010)
>>       
>> org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1908)
>>        org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1679)
>>
>> 
>> org.apache.openjpa.kernel.DelegatingBroker.flush(DelegatingBroker.java:989)
>>
>>
>> org.apache.openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java:592)
>>
>>
>> org.apache.openejb.persistence.JtaEntityManager.flush(JtaEntityManager.java:130)
>>        ejb.HelloBean.createPerson(HelloBean.java:31)
>>        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>
>>
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>
>>
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>        java.lang.reflect.Method.invoke(Method.java:597)
>>
>>
>> org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:158)
>>
>>
>> org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:141)
>>
>>
>> org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:122)
>>
>>
>> org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:221)
>>
>>
>> org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:174)
>>
>>
>> org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217)
>>
>>
>> org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77)
>>
>>
>> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:281)
>>        $Proxy46.createPerson(Unknown Source)
>>        test.HelloServlet.doGet(HelloServlet.java:31)
>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
>>        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
>>
>>
>> It's obvious, from
>> INSERT INTO person (person_id, address, name)
>>    VALUES (?, ?, ?)
>> [params=(long) 2201, (String) any address, (String) name]} [code=-10,
>> state=23000]
>>
>> the parms values were taken, but did not pass/forward to database - this
>> should not be in ejb3 package.
>>
>> Can anyone tell how to fix it?
>>
>> Thanks
>> --
>> John
>> --
>> View this message in context:
>> http://n2.nabble.com/did-pass-params---Attempt-to-insert-null-into-a-non-nullable-column-tp3190581p3190581.html
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://n2.nabble.com/did-pass-params---Attempt-to-insert-null-into-a-non-nullable-column-tp3190581p3191873.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message