We are using GAE with JDO2.3 and have this code:
public void submit_job (HttpSession session, BlobKey blobKey) throws Exception {
// START TRANSACTION
PersistenceManager pm = PMF.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
tx.begin();
// GET JOB AND MEMBER FROM DATASTORE
Key jobKey = (Key)session.getAttribute("jobkey");
String userName = session.getAttribute("username").toString();
Job job = pm.getObjectById(Job.class, jobKey);
Member m = pm.getObjectById(Member.class, username);
// STORE JOB INFORMATION IN DATASTORE
Date now = new Date();
job.caricature = blobKey;
job.whenSubmitted = now;
job.whenFinished = now;
pm.makePersistent(job);
pm.flush();
log.warning("submit_job: updating job " + job.key);
// UPDATE MEMBER INFORMATION
m.numSubmittedJobs++;
pm.makePersistent(m);
pm.flush();
log.warning("submit_job: updating user " + username);
// COMPLETE TRANSACTION
tx.commit();
pm.close();
log.warning("transaction completed? " + !tx.isActive());
}
The symptoms:
no exception is thrown, everything runs fine
at the end, the transaction is properly completed ("transaction completed? true")
following queries can read the updated data from the Member and Job objects
BUT
the information does not show up in the datastore manager
after restarting the instance, the JDO objects have their old values. ALL CHANGES ARE LOST.
Here is our jdoconfig.xml:
<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/>
<property name="javax.jdo.option.ConnectionURL" value="appengine"/>
<property name="javax.jdo.option.NontransactionalRead" value="true"/>
<property name="javax.jdo.option.NontransactionalWrite" value="true"/>
<property name="javax.jdo.option.RetainValues" value="true"/>
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/>
<property name="datanucleus.appengine.singletonPMFForName" value="true"/>
<property name="datanucleus.appengine.datastoreEnableXGTransactions" value="true"/>
</persistence-manager-factory>
</jdoconfig>
and the persistence.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="transactions-optional">
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<properties>
<property name="datanucleus.NontransactionalRead" value="true"/>
<property name="datanucleus.NontransactionalWrite" value="true"/>
<property name="datanucleus.ConnectionURL" value="appengine"/>
</properties>
</persistence-unit>
</persistence>
Any help is appreciated, we already put a lot of effort into this topic, but are unable to solve it yet.
Thanks!
So you're setting public fields of a persistable class, and somehow expect the persistence mechanism to know about this. As per the JDO spec, you should use setters, or annotate the class doing the setting as PersistenceAware.
And look at the log too, since it tells you what is happening
Related
I have MDB configured to receive incoming message and persist it via a SLSB using JPA (eclipseLink). The database inserts work for one off message but in load conditions (3 or 4 messages per second), Data is not persisted in DB. I can see sql Insert queries in the log but no data in DB.
Persistence File:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<!-- <persistence-unit name="mainPU" transaction-type="JTA"> -->
<persistence-unit name="mainPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>ecpcPool</jta-data-source>
<class>com.fc.ECP.domain.Address</class>
<class>com.fc.ECP.domain.Customer</class>
<class>com.fc.ECP.domain.DocumentationSignature</class>
<class>com.fc.ECP.domain.EcpSystem</class>
<class>com.fc.ECP.domain.EcpTransaction</class>
<class>com.fc.ECP.domain.EcpWkflw</class>
<class>com.fc.ECP.domain.EidVerify</class>
<class>com.fc.ECP.domain.EsignDetail</class>
<class>com.fc.ECP.domain.Finpln</class>
<class>com.fc.ECP.domain.FinplnDocumentation</class>
<class>com.fc.ECP.domain.ThirdPartyCrdntl</class>
<class>com.fc.ECP.domain.ThirdPartyDocumentation</class>
<class>com.fc.ECP.domain.TransactionType</class>
<class>com.fc.ECP.domain.Advice</class>
<class>com.fc.ECP.domain.Advcln</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<property name="eclipselink.target-server" value="WebLogic_10"
/>
<property name="javax.persistence.jtaDataSource"
value="ecpcPool" />
<!-- <property name="javax.persistence.jtaDataSource"
value="jdbc/MicrosoftSQLServer"/> -->
<!-- <property name="javax.persistence.jtaDataSource"
value="ecp_prx_ds"/> -->
<property name="eclipselink.target-database"
value="org.eclipse.persistence.platform.database.SQLServerPlatform" />
<property name="eclipselink.session.customizer"
value="com.fc.adr.jpa.JPASessionCustomizer" />
<property name="com.fc.adr.jpa.schema" value="$(mainPU.schema)"
/>
<property name="com.fc.adr.jpa.schema.sequences"
value="$(mainPU.schema.sequences)" />
<property name="eclipselink.logging.logger"
value="DefaultLogger" />
<property name="eclipselink.logging.level.sql" value="FINE" />
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.logging.parameters" value="true" />
<property name="eclipselink.persistence-context.flush-mode"
value="commit" />
</properties>
</persistence-unit>
</persistence>
Switch to EJB2 style config for MDB.
Underlying Cause:
The EJB3 style MDB ‘s methods are wrapped by CDI injection.
One of the wrapper classes in the stack trace is: com.oracle.pitchfork.intercept.MethodInvocationInvocationContext
which is in a spring framework module jar in weblogic
MethodInvocationInvocationContext looks for a WebServiceContext in the JNDI tree at “java:comp/WebServiceContext”
Having a jax-ws service puts a WebServiceContext at “java:comp/WebServiceContext”
If the WebServiceContext is present, then MethodInvocationInvocationContext tries to access its values for the MessageDrivenContext
The spec requires WebServiceContext to throw an IllegalStateException if it is accessed outside of a web service call
I'm using Liquibase (v 3.0.7) together with Spring (v 4.0.0):
<!-- Liquibase configuration -->
<bean id = "liquibase" class = "liquibase.integration.spring.SpringLiquibase">
<property name = "dataSource" ref = "dataSource" />
<property name = "changeLog" value = "classpath:database/changelog.xml" />
</bean>
Once I've deployed my Spring application, Liquibase will create two tables: databasechangelog and databasechangeloglock. Is there a way to rename those two tables?
You can use system properties to override the default table names.
Or you can use small workaround to setup this names in spring configuration, check this answer for Java configuration - https://stackoverflow.com/a/50644347 or you can use this for xml configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="liquibaseSystemPropsSetter"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" value="#{#systemProperties}"/>
<property name="targetMethod" value="putAll"/>
<property name="arguments">
<util:properties>
<prop key="liquibase.databaseChangeLogTableName">${application.liquibase.change.log.table.name}</prop>
<prop key="liquibase.databaseChangeLogLockTableName">${application.liquibase.change.log.lock.table.name}
</prop>
</util:properties>
</property>
</bean>
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase"
depends-on="liquibaseSystemPropsSetter"
p:dataSource-ref="localDataSource"
p:changeLog="classpath:${application.liquibase.change.log.path}"
p:shouldRun="${application.liquibase.should.run}"/>
</beans>
I have an arquillian unit test that is writing a Note and passing the unit tests.
Now I would like to actually view what is being persisted into my SQLServer database.
When I open up SQLServer, I see my "Note" table, with all of the requisite columns...but there's no data.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="noteUnit"
transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/jdbc/datasources/notes</jta-data-source>
<properties>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2005Dialect" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
<property name="hibernate.hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
</persistence>
I've tried various values for hbm22ddl.auto--'create-drop', 'update','validate', but since my test passes, I assume that the new rows are being inserted and then immediately removed by arquillian after the unit test?
Unit test below passes--meaning arquillian's xml file and all the other assorted plumbing appears to be set up correctly. Is there a setting somewhere to save all the data that's being inserted?
private NoteEntity createNote(){
NoteEntity note = new NoteEntity();
note.setGuid("123456789");
note.setAuthorId("12345");
return note;
}
#Test
public void createNoteTest(){
NoteEntity note1 = createNote();
mEntityManager.persist(note1);
Assert.assertNotNull(note1.getId());
}
Generally, jUnit are configured so that their transaction is in defaultrollback=true mode. This is done to avoid inserting test data in your database. You will probably find the configuration over your class definition or in an extended class.
Example for jUnit with Spring IOC configuration :
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = "classpath*:myPath/spring*Context.xml")
#TransactionConfiguration(defaultRollback = true)
#Transactional
public abstract class AbstactSpringTestCase {
...
}
I have the following JPA code, with all the values checked (ticket contains a valid bean, it ends without exception, etc.) It is executed, it does not throw any exceptions, yet in the end no data is written into the table.
I tried also retrieving a bean from the table, it also "works" (it is empty, so no data is returned).
The setup is
JBoss 6.1 Final
SQLServer 2008 Express (driver SQL JDBC 3 from MS)
The persistence code:
public String saveTicket() {
System.out.println("Controller saveTicket() ");
EntityManagerFactory factory = Persistence.createEntityManagerFactory("GesMan"); /* I know it would be better to share a single instance of factory, this is just for testing */
EntityManager entityMan = factory.createEntityManager();
entityMan.persist(this.ticket);
entityMan.close();
}
The persistence unit is
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="GesMan" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/GesManDS</jta-data-source>
<class>es.caib.gesma.gesman.Ticket</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
The datasource
<datasources>
<local-tx-datasource>
<jndi-name>GesManDS</jndi-name>
<connection-url>jdbc:sqlserver://spsigeswnt14.caib.es:1433;DatabaseName=TEST_GESMAN</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<user-name>thisis</user-name>
<password>notthepassword</password>
<check-valid-connection-sql>SELECT * FROM dbo.Ticket</check-valid-connection-sql>
<metadata>
<type-mapping>MS SQLSERVER</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
call entityMan.flush() or transaction.commit() befor closing it, otherwise it will discard all changes queued on close.
In the end it looks like I was using the wrong approach.... In JBoss you can`t (better said, I could not get to) access JPA directly (as you would do in JSE).
I ended creating an EJB (with transactions) and passing all JPA logic there.
PS: Of course, if I am wrong please tell me (now it is more of an academic issue, but still I want to know)
I'm trying to write a Vaadin application on GAE platform with using JDO, and when I want to call this method:
public void createUser(String login, String password, String email) {
PersistenceManager pm = PMF.get().getPersistenceManager();
User user = new User(login, password, email);
try {
pm.makePersistent(user);
} finally {
pm.close();
}
}
I get this error:
(...)Caused by: javax.jdo.JDOFatalUserException: A property named javax.jdo.PersistenceManagerFactoryClass must be specified, or a jar file with a META-INF/services/javax.jdo.PersistenceManagerFactory entry must be in the classpath, or a property named javax.jdo.option.PersistenceUnitName must be specified.
NestedThrowables:
javax.jdo.JDOUserException: You have either specified for this PMF to use a "persistence-unit" of "transactions-optional" (yet this doesnt exist!) or you called JDOHelper.getPersistenceManagerFactory with "transactions-optional" as the name of a properties file (and this doesnt exist in the CLASSPATH)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:856)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:1092)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:914)
at myapp.PMF.(PMF.java:8)
... 43 more
Caused by: javax.jdo.JDOUserException: You have either specified for this PMF to use a "persistence-unit" of "transactions-optional" (yet this doesnt exist!) or you called JDOHelper.getPersistenceManagerFactory with "transactions-optional" as the name of a properties file (and this doesnt exist in the CLASSPATH) (...)
I've searched the Google and found some solutions for this problem, but none works for my app (or I'm doing something incorrectly).
For eg.this wouldn't work. Oh, and I have the jdoconfig.xml file in META-INF.
If anyone had similar problem, and he'd like to share his wisdom I would be very appreciate.
EDIT: jdoconfig file:
<?xml version="1.0" encoding="utf-8"?>
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">
<persistence-manager-factory name="transactions-optional">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory" />
<property name="javax.jdo.option.ConnectionURL" value="appengine" />
<property name="javax.jdo.option.NontransactionalRead" value="true" />
<property name="javax.jdo.option.NontransactionalWrite"
value="true" />
<property name="javax.jdo.option.RetainValues" value="true" />
<property name="datanucleus.appengine.autoCreateDatastoreTxns"
value="true" />
</persistence-manager-factory>
</jdoconfig>
Got it!
jdoconfig.xml
file was in
\war\META-INF
directory that Eclipse had created. Should be in
\war\WEB-INF\classes\META-INF
Dumb mistake...