WebLogic 12c (12.2.1.4) with Hibernate 5.4 - spring

I have an application deployed on WebLogic 12c (12.2.1.4) using Hibernate 5.2.18. Weblogic 12c doc references JPA 2.1 compatibility and Hibernate 5.3+ requires JPA 2.2. Can I prepend the JPA 2.2 API to my startup classpath and use Hibernate 5.3+ or should I stick with Hibernate 5.2 for the time being?

Yes, this configuration is possible.
To avoid conflicts with WebLogic built-in JPA capabilities you should do the following:
According to this
In a full Java EE environment, consider obtaining your EntityManagerFactory from JNDI. Alternatively, specify a custom persistenceXmlLocation on your LocalContainerEntityManagerFactoryBean definition (for example, META-INF/my-persistence.xml) and include only a descriptor with that name in your application jar files. Because the Java EE server looks only for default META-INF/persistence.xml files, it ignores such custom persistence units and, hence, avoids conflicts with a Spring-driven JPA setup upfront.
You can use something like this in the spring context config.
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<!-- ... -->
<jee:jndi-lookup id="DS" jndi-name="appDS" />
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:META-INF/app-persistence.xml" />
<property name="dataSource" ref="DS" />
</bean>
<!-- ... -->
</beans>
According to this
To configure the FilteringClassLoader to specify that a certain package is loaded from an application, add a prefer-application-packages descriptor element to weblogic-application.xml which details the list of packages to be loaded from the application.
You should add the following snippet to your META-INF/weblogic-application.xml
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application>
<prefer-application-packages>
<!-- ... -->
<package-name>javax.persistence.*</package-name>
</prefer-application-packages>
</weblogic-application>

Related

Specify default Spring profile

Is there anyway to specific the default profile directly in the Spring XML
<beans profile="Development">
<!-- Load Development beans -->
</beans>
<beans profile="Production">
<!-- Load Production beans -->
</beans>
Note, I don't want to do this programmatically, as command-line property, environment variable or web.xml (its not a web app)
I want to do it directly in the xml something like:
<property name="spring.profiles.default" value="Production">

spring batch use data source instead of jdbc using batch-db2.properties

I am fairly new to spring batch. I have it working embedded inside my spring mvc web application. It is using a db2 database data store to log job information. At present my batch-db2.properties reads as...
batch.jdbc.driver=com.ibm.db2.jcc.DB2Driver
batch.jdbc.url=<<my database url>>
batch.jdbc.user=<<my database user>>
batch.jdbc.password=<<my database password>>
batch.schema=<<my database scehma>>
batch.jndi.name=jdbc/<<my jndi url>>
So I've set both jdbc properties and well as the jndi property. The jobs are running fine but my question is what type of connection is my spring batch installation using.
If both are set does it use jdbc or jndi? Also can someone point me to the spring batch documentation page where it gives more information about these settings. I could not find it.
Here is my data source configuration....
<beans profile="server">
<bean id="ePosDataSource"
class="org.springframework.jndi.JndiObjectFactoryBean"
p:jndiName="java:comp/env/jdbc/reportingManagerDataSource"
p:lookupOnStartup="false"
p:cache="true"
p:proxyInterface="javax.sql.DataSource"/>
<jee:jndi-lookup id="ePosDataSource"
jndi-name="jdbc/reportingManagerDataSource"
cache="true"
resource-ref="true"
lookup-on-startup="false"
proxy-interface="javax.sql.DataSource"/>
<bean id="custDbDataSource"
class="org.springframework.jndi.JndiObjectFactoryBean"
p:jndiName="java:comp/env/jdbc/reportingManagerCustDbDataSource"
p:lookupOnStartup="false"
p:cache="true"
p:proxyInterface="javax.sql.DataSource" />
<jee:jndi-lookup id="custDbDataSource"
jndi-name="jdbc/reportingManagerCustDbDataSource"
cache="true"
resource-ref="true"
lookup-on-startup="false"
proxy-interface="javax.sql.DataSource"/>
</beans>
thanks!

Dependency version issue with Spring, Spring Neo4j and Neo4j

I am trying to setup a Java project which uses Spring-Neo4j and Neo4j but unable to get around with dependency issues. I am using maven for dependency management and have tried several version combinations of Spring, Spring Neo4j and Neo4j.
spring: 3.2.6.RELEASE
spring-data-neo4j: 3.0.0.RELEASE
neo4j: 2.0.1
application-context.xml file
<neo4j:config storeDirectory="data/graph.db" />
Error:
Caused by: org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException: Failed to start Neo4j with an older data store version. To enable automatic upgrade, please set configuration parameter "allow_store_upgrade=true"
at org.neo4j.kernel.impl.storemigration.ConfigMapUpgradeConfiguration.checkConfigurationAllowsAutomaticUpgrade(ConfigMapUpgradeConfiguration.java:39)
at org.neo4j.kernel.impl.storemigration.StoreUpgrader.attemptUpgrade(StoreUpgrader.java:71)
at org.neo4j.kernel.impl.nioneo.store.StoreFactory.tryToUpgradeStores(StoreFactory.java:144)
at org.neo4j.kernel.impl.nioneo.store.StoreFactory.newNeoStore(StoreFactory.java:119)
at org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.start(NeoStoreXaDataSource.java:323)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:503)
... 64 more
I have enabled allow_store_upgrade=true in my neo4j.properties file.
Your embedded neo4j most likely doesn't pick up the neo4j file (this documentation says you need to set it manually).
Initialise your neo4j like this
<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase"
destroy-method="shutdown">
<constructor-arg index="0" value="target/config-test"/>
<!-- optionally pass in neo4j-config parameters to the graph database
<constructor-arg index="1">
<map>
<entry key="allow_store_upgrade" value="true"/>
</map>
</constructor-arg>
-->
</bean>
<neo4j:config graphDatabaseService="graphDatabaseService"/>
Source:
http://docs.spring.io/spring-data/data-neo4j/docs/3.0.1.RELEASE/reference/html/setup.html#d0e3597
I'm trying to use spring-data-neo4j 3.1.1.RELEASE and neo4j 2.1.2 and I think this is incomplete. Indeed, at least with these versions, map is not optionnal. Moreover there is a third mandatory argument in constructor of type Dependencies.
The problem is that I don't really know what is this third parameter and moreover EmbeddedGraphDatabase and Dependecies are deprecated. Do you know which is the good way to start a webapp (with these versions) in embedded mode ?

How do I access TomEE's JTA transaction manager?

I have an application that uses Spring's declarative transaction management. How can I deploy this in a TomEE+ container so that the application uses TomEE's JTA transaction manager?
More specifically, how can I refer to the built-in transaction manager from within Spring's "application-context.xml" file?
Spring's transaction management configuration seems to want to look up the transaction manager either by a bean reference or by JNDI lookup; I have spent a day researching this and looking at source code; I have found a lot of discussion of the issue (references below) but no definitive how-to.
What I have in the application's META-INF/persistence.xml is this:
<persistence-unit name="myPersistenceUnit" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>myDs-managed</jta-data-source>
<non-jta-data-source>myDs-unmanaged</non-jta-data-source>
<properties>
<property name="openjpa.jdbc.DBDictionary"
value="org.apache.openjpa.jdbc.sql.PostgresDictionary"/>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
<property name="openjpa.Run
<property name="openjpa.Log" value="slf4j" />
</properties>
</persistence-unit>
And, in the applications META-INF/spring/applicationContext.xml file I have this: (I have tried various values for transactionManagerName as suggested in various discussions of the topic, as it appears to be non-standard across application servers
<tx:annotation-driven mode="aspectj" transaction-manager="txManager" />
<bean class="org.springframework.transaction.jta.JtaTransactionManager"
id="txManager">
<property name="transactionManagerName"
value=" java:comp/TransactionManager"/>
</bean>
Here's an example that is claimed to work for JBoss: Spring JTA configuration - how to set TransactionManager?
Here's a near miss that won't work in an xml configuration file: https://issues.apache.org/jira/browse/TOMEE-38
Here's how to do it within java code if you have your hands on initialContext: http://osdir.com/ml/users.openejb.apache.org/2012-11/msg00110.html
[Edit: The Tomee documentation talks about how to declare a transaction manager, but it says to do it in Tomee.xml, which belongs to the server and not to the individual webapp; I want to configure the transaction manager for a single app and not for the whole server: http://tomee.apache.org/containers-and-resources.html]
Have you tried java:comp/env/TransactionManager for the transactionManagerName?
,
Also have you declared the TransactionManager and DataSource as described here: http://tomee.apache.org/containers-and-resources.html?

Hibernate DDL database generation stopped when I use Maven

Previously, my Java web projects used Eclipse-ordinary structure, and at the start of the container (in case, Tomcat), Hibernate generated the schemes correctly.
Now I'm using Maven infrastructure. I've relocated the needed files and configured all well (I think, because all is working right: Spring is starting, Hibernate is connecting the database - when it was previously created and there's some data to fetch). I've tested all CRUD operations and it's working.
The problem is that Hibernate refuses to generate the schemes (DDL) as it did when over Eclipse-ordinary infrastructure.
Additional information:
My persistence.xml is almost empty (as always) because Spring applicationContext.xml is starting it. I have not changed the file, it continues the same way as before.
<!-- Location: src/main/resources/META-INF/persistence.xml -->
<persistence>
<persistence-unit name="jpa-persistence-unit" transaction-type="RESOURCE_LOCAL"/>
</persistence>
Part of the Spring configuration goes here (applicationContext.xml):
<!-- Location: src/main/webapp/WEB-INF/applicationContext.xml -->
<!-- ... -->
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="[DATABASE-NAME]" />
<property name="showSql" value="true" />
<property name="generateDdl" value="true" /> <!-- THIS CONFIGURATION WORKED PREVIOUSLY, NOW WITH MAVEN, IT'S IGNORED -->
<property name="databasePlatform" value="[DIALECT]" />
</bean>
<!-- ... -->
I'm not using any Maven Hibernate plugin, because I just want the default behavior that occurred earlier.
Did Maven invalidate this "generateDdl" property!? Why!? What should I do!? I can't find any solution.
I found out the solution.
Maven has any fault about that.
Hibernate was not able to create my database because the "DIALECT" was wrong.
I remembered that I changed the dialect from MySQL to MySQL-InnoDB. Hibernate was logging this problem but I couldn't see it because the slf4j-simple dependency was not explicity imported.
Thank you for your time, Shawn.

Resources