Persistence.xml for JBoss AS 7.1.1 - jboss

I have a client and server setup to run with JBoss AS 7.1.1 and I have a question about my persistence.xml. Currently it looks like this:
<persistence>
<persistence-unit name="GrahamsProj">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/WorkCenterDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
</properties>
</persistence-unit>
</persistence>
I have persistence.xml in the META-INF folder of my server. I must be missing some properties though because I'm getting this error when I try to query the database I'm connected to.
11:35:07,840 ERROR [org.jboss.ejb3.invocation] (EJB default - 1) JBAS014134:
EJB Invocation failed on component GrahamsProjBean for method public abstract
void grahamsprojserver.session.interfaces.GrahamsProjBeanRemote.test(): javax.ejb.EJB
Exception: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException:
Schemas is not mapped [FROM Schemas s]
Is there something I'm missing?

you need to include all your model classes in persistence.xml. example:
<persistence>
<persistence-unit name="GrahamsProj">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/WorkCenterDS</jta-data-source>
<class>your.class.model.Example</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
</properties>
</persistence-unit>
</persistence>

You would probably need to update the hibernate.dialect property too. In your example you are using "org.hibernate.dialect.HSQLDialect" and you use Oracle drivers, e.g. "oracle.jdbc.OracleDriver". If you are using Oracle database, you need to update hibernate dialect, e.g. "org.hibernate.dialect.Oracle10gDialect".
Here's your updated code:
<persistence>
<persistence-unit name="GrahamsProj">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/WorkCenterDS</jta-data-source>
<class>your.class.model.Example</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
</properties>
</persistence-unit>
</persistence>

Related

JPA Query don't find EntityClass

Well, i'm trying to execute a simple query but i always got a "Not Mapped Entity". See my query :
"SELECT c FROM MyOwnClass c WHERE c.filter = :filter ORDER BY c.filter";
But if i put the qualified name of class "br.com.myproject.MyOwnClass" the query is executed.
This is my persistence.xml file:
<persistence-unit transaction-type="RESOURCE_LOCAL" name="myPU">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>java:jboss/datasources/myDS</non-jta-data-source>
<class>br.com.myproject.MyOwnClass</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="none"/>
<property name="hibernate.connection.characterEncoding" value="UTF-8"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="false"/>
</properties>
</persistence-unit>
Are your entity classes in a different package than your query code? You probably just need to add an import:
import br.com.myproject.MyOwnClass;

Not generating schema in JPA using openjpa H2

I am trying to use an H2 in memory database to do some testing on my JPA entities. I am still stuck at the point of creating the schema. my persistance unit looks like this
<persistence-unit name="TEST_DS" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>com.domain.entities.ThisEntity</class>
<properties>
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="sa" />
<property name="openjpa.ConnectionURL" value="jdbc:h2:mem:test2" />
<property name="openjpa.ConnectionDriverName" value="org.h2.Driver"/>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true,schemaAction='dropDB,add')" />
</properties>
</persistence-unit>
I have tried various combinations of openjpa & javax.persistance properties without luck.
The exception I get is
org.apache.openjpa.persistence.PersistenceException: Schema "DBM" not found.
The schema exists in my entities

Integrate BoneCP and EclipseLink with LOCAL_RESOURCE transaction-type

I am setting up a minimal working example where I use EclipseLink in a Java EE (JSF) project. My example works perfectly with the following configuration and code:
persistence.xml
<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="issat_PU_Local" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>pro.entity.Utilisateur</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/issat" />
<property name="javax.persistence.jdbc.user" value="java" />
<property name="javax.persistence.jdbc.password" value="JaVa" />
<property name="eclipselink.logging.level.sql" value="FINE" />
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
</persistence>
Since I don't want to use JTA I am using RESOURCE_LOCAL as transaction type and perfectly leaving with "manually" handling transaction inside my DAO.
I now want to use BoneCP connection pool with my example.
How should I precisely modify my persistence.xml to do that? I found many configuration examples in the internet using also Hibernate, but I want to stay with EclipseLink.
I couldn't do it with bonecp, but I could get a pool connection with C3PO.
I followed this link : http://javabeginnerstutorial.com/hibernate/connection-pooling-with-hibernate-4/
I copied the dependency and the properties but, instead of <property name="hibernate.c3p0.min_size">1</property> put the value in the tag like this<property name="hibernate.c3p0.min_size" value="1"/>, otherwise I got an error.
Finally mi persitence.xml look this way:

JPA, EclipseLink, PostgreSQL and schemas

I want to develop a Java EE application with JPA (EclipseLink implementation) and PostgreSQL as database.
I chose to have one database and multiples schemas instead of having multiples databases and one schema per database.
So, in my persistence.xml I have something like that :
<persistence-unit name="00" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>todo</jta-data-source>
<class>...</class>
<class>...</class>
<properties>
<property name="javax.persistence.target-database" value="PostgreSQL" />
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/testdb;create=true" />
<property name="javax.persistence.jdbc.user" value="user" />
<property name="javax.persistence.jdbc.password" value="userpwd" />
</properties>
</persistence-unit>
<persistence-unit name="01" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>todo</jta-data-source>
<class>...</class>
<class>...</class>
<properties>
<property name="javax.persistence.target-database" value="PostgreSQL" />
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/testdb;create=true" />
<property name="javax.persistence.jdbc.user" value="user" />
<property name="javax.persistence.jdbc.password" value="userpwd" />
</properties>
</persistence-unit>
I can easily reference persistence unit :
EntityManagerFactory emf = Persistence.createEntityManagerFactory("01");
EntityManager em = emf.createEntityManager();
but how can I store information about schemas in persistence.xml ? I want to access schema 00 or 01 in testdb database.
I probably could change schema via native SQL directly but is there a way to bind schema to persistence unit ?
Thank you
This same question was asked and answered here:
JPA - EclipseLink - How to change default schema
You can override the schema for the entire persistence unit using an orm.xml file, or define it within each table annotation or xml element as needed.

How can one debug/fix an everlasting null return from EntityManager's find?

I am following this example
. I keep getting this error whenever calling upon find:
java.lang.NullPointerException
at LoginAction.service(LoginAction.java:41)
at Dispatcher.doWork(Dispatcher.java:82)
at Dispatcher.doGet(Dispatcher.java:64)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:315)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
I have no idea where to start looking. The 41th line is operator.findOperator(1), where
#EJB
private OperatorBeanService operator;
I'm trying to do this on a Glassfish 2.1. This is the persistence:
<persistence-unit name="persistMe" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/peciu</jta-data-source>
<properties>
<property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
<property name="eclipselink.target-database" value="myDB"/>
<property name="eclipselink.target-server" value="host"/>
<property name="eclipselink.logging.level" value="ALL"/>
</properties>
</persistence-unit>
I've tried a separate JPA project with this persistence:
<persistence-unit name="OperatorService" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>Operator</class>
<properties>
<property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
<property name="eclipselink.jdbc.driver" value="COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver"/>
<property name="eclipselink.jdbc.url" value="jdbc:db2://host:50000/myDB"/>
<property name="eclipselink.jdbc.user" value="user"/>
<property name="eclipselink.jdbc.password" value="pass"/>
</properties>
</persistence-unit>
and it worked just fine, returning the result from the OPERATOR table.
I don't know what I'm missing. Thank you for your time. Iulia
You need to figure out why your OperatorBeanService isn't being injected(#EJB annotation).
I'm slightly confused though, you are following a WebSphere tutorial/example using glassfish? Perhaps you could try this with WAS to see if it works? Sorry about the non-answer answer, but I don't have much to go off.
-Rick