Creating table form JPA Entity fails - jpa

I have set-up a completely new JPA Project in Eclipse (Kepler)...after I ran into issues in an existing project.
I intend to write a JpaEntity and let Eclipse (or JPA respectively) create the respective table in the database but this fails and I can't figure out the reason.
Eclipse tells me Table "myentrances" cannot be resolved. Of course...it doesn't exist by now. ...it shall be created yet.
Here's my JpaEntity:
#Entity
#Table(name="myentrances")
#NamedQuery(name="MyEntrance.findAll", query="SELECT e FROM MyEntrance e")
#TableGenerator(name = "myentrances")
#Access(PROPERTY)
public class MyEntrance implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int entranceId;
#OneToOne(cascade = CascadeType.ALL, optional = false, fetch = FetchType.EAGER, orphanRemoval = true)
#PrimaryKeyJoinColumn
private Address address;
#Column(nullable=false)
private double maxHeight;
#Column(nullable=false)
private String maxHeightUom;
private static final long serialVersionUID = 1L;
public MyEntrance() {
super();
}
public int getEntranceId() {
return this.entranceId;
}
public void setEntranceId(int entranceId) {
this.entranceId = entranceId;
}
public Address getAddress() {
return this.address;
}
public void setAddress(Address address) {
this.address = address;
}
public double getMaxHeight() {
return this.maxHeight;
}
public void setMaxHeight(double maxHeight) {
this.maxHeight = maxHeight;
}
public String getMaxHeightUom() {
return this.maxHeightUom;
}
public void setMaxHeightUom(String maxHeightUom) {
this.maxHeightUom = maxHeightUom;
}
}
Here's my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="JpaTest" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.tsystems.ikt.model.Address</class>
<class>com.tsystems.ikt.model.MyEntrance</class>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/myDb"/>
<property name="javax.persistence.jdbc.user" value="root"/>
</properties>
</persistence-unit>
Here's the exception I get:
[EL Config]: metadata: The element [method getAddress] is being defaulted to a one to one mapping.
[EL Config]: metadata: The target entity (reference) class for the one to one mapping element [method getAddress] is being defaulted to: class com.tsystems.ikt.model.Address.
[EL Config]: metadata: The access type for the persistent class [class com.tsystems.ikt.model.Address] is set to [FIELD].
[EL Config]: metadata: The access type for the persistent class [class com.tsystems.ikt.model.MaiEntrance] is set to [FIELD].
[EL Config]: metadata: The alias name for the entity class [class com.tsystems.ikt.model.MyEntrance] is being defaulted to: MyEntrance.
[EL Config]: metadata: The column name for element [getEntranceId] is being defaulted to: ENTRANCEID.
[EL Config]: metadata: The column name for element [getMaxHeightUom] is being defaulted to: MAXHEIGHTUOM.
[EL Config]: metadata: The column name for element [getMaxHeight] is being defaulted to: MAXHEIGHT.
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: org.eclipse.persistence.dynamic.DynamicClassLoader#580760d7
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [JpaTest] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class com.tsystems.ikt.model.MyEntrance] has no primary key specified. It should define either an #Id, #EmbeddedId or an #IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.buildEntityManagerFactory(Main.java:94)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:80)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:68)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [JpaTest] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class com.tsystems.ikt.model.MyEntrance] has no primary key specified. It should define either an #Id, #EmbeddedId or an #IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:1954)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1945)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:98)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:96)
... 5 more
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [JpaTest] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class com.tsystems.ikt.model.MyEntrance] has no primary key specified. It should define either an #Id, #EmbeddedId or an #IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:230)
... 9 more
Caused by: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class com.tsystems.ikt.model.MyEntrance] has no primary key specified. It should define either an #Id, #EmbeddedId or an #IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
at org.eclipse.persistence.exceptions.ValidationException.noPrimaryKeyAnnotationsFound(ValidationException.java:1422)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.validatePrimaryKey(EntityAccessor.java:1536)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.processMappingAccessors(EntityAccessor.java:1243)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.process(EntityAccessor.java:697)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage2(MetadataProject.java:1793)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:576)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:585)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1869)
... 7 more
I am only using field access (in Address as well).
I am using Eclipselink 2.5.1.
By the way:
Isn't it possible to create a table for just a single newly created JpaEntity? Do I ever have to chose MyProject-->JPA Tools-->Generate TableS from EntitieS? This seems to create ALL existing tables as well, does it? What if I have already created a bunch of tables and now just want to add one further table based by a newly created JpaEntity?

The default access mode for entities in JPA is AccessType.FIELD.
You have overwritten it by declaring #Access(PROPERTY) for the entity therefore #Id annotation is unnoticed by the persistence provider while processing metadata. Try to remove #Access(PROPERTY) annotation to solve the problem.
What if I have already created a bunch of tables and now just want to
add one further table based by a newly created JpaEntity?
It depends from a scenario:
if dropping existing tables is forbidden for any reason (i.e. in case of legacy database): leave create-tables in persistence.xml so that the provider creates the table based on a new entity (i.e. MyEnterance); for already existing table you may use DROP TABLE myentrances later on to remove the corresponding table and recreate it automatically during the next start up - the provider will take care of recreating the entity from scratch
if dropping existing tables is allowed: replace create-tables with drop-and-create-tables in persistence.xml - the provider will take care of recreating the whole entity model from scratch

Related

Functional operators causes JPA to crash? (Bug?)

I'm having a very strange problem with JPA and Java 8 functional programming.
I have a Student and Presentation class and their relationship is bidirectional. Everything worked fine in Java 7, but I just switched to Java 8.
This works (visible is private, has no setters):
public static void setAllVisible(boolean visible) {
for (Presentation presentation : new PresentationRepository().findAll()) {
presentation.visible = visible;
}
}
This crashes:
public static void setAllVisible(boolean visible) {
new PresentationRepository().findAll().forEach(x -> x.visible = visible);
//same for new PresentationRepository().findAll().stream().forEach(x -> x.visible = visible);
}
Which gives this exception multiple times:
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader#4554617c
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [BachelorproefPU] failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class models.users.Student] uses a non-entity [class models.planning.Presentation] as target entity in the relationship attribute [field presentation].
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:107)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at persistence.JPAEntityManager.getEntityManagerFactory(JPAEntityManager.java:45)
at models.repositories.Repository.<init>(Repository.java:23)
at models.repositories.UserRepository.<init>(UserRepository.java:15)
at main.DbInitializer.<init>(DbInitializer.java:27)
at main.DbInitializer.main(DbInitializer.java:23)
I'm pretty sure the persistence.xml is configured correctly (because it works without Java 8) and all classes are included and have #Entity. It's also not the Student class, because if I comment that out, the error just gives another class.
What's causing this? Maybe it's also worth mentioning that I get a compile crash once a while and that they ask me to send the project to Oracle.
Think you'll find that current EclipseLink doesn't support Java 1.8 syntaxis; look at
https://github.com/averri/jpa-lambda-integration-test
I use DataNucleus v4.0 for my projects and works for Java 1.8

Lazy loading of #ManyToOne relation fails with GlassFish 4 / EclipseLink

GlassFish 4 (actually its JPA implementation, i.e. EclipseLink) fails to lazy load a #ManyToOne JPA relation from our Java EE 7 application. Default/eager loading is ok, but not lazy loading.
The relation in the 'Student' entity is:
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "addr_id")
private Address address;
The (simplified) persistence.xml looks like:
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="foo-PU" transaction-type="JTA">
<jta-data-source>jdbc/foo-DS</jta-data-source>
<class>foo.domain.Student</class>
<class>foo.domain.Address</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-database" value="PostgreSQL"/>
<property name="eclipselink.logging.level" value="FINE"/>
</properties>
</persistence-unit>
</persistence>
The application uses several API: PrimeFaces, JSF 2.2, CDI 1.1, JPA 2.1.
Also note that the EntityManager are not obtained by injection into session EJB, but manually created using Persistence.createEntityManagerFactory(...) then emf.createEntityManager(...).
The error message is:
WARNING: Reverting the lazy setting on the OneToOne or ManyToOne attribute [address] for the entity class [class foo.domain.Student] since weaving was not enabled or did not occur.
My understanding is that, for some reason, the dynamic weaving of entities is not enabled. For a Java EE application it should be, as suggested by http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving.
For the record, if we try to force the weaving using this:
<property name="eclipselink.weaving" value="true"/>
in the persistence.xml, then we get another error message:
SEVERE: Error Rendering View[/student/studentList.xhtml]
javax.el.ELException: /student/studentList.xhtml #24,81 value="#{studentController.selectedCode}": Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28022] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Value [true] for the property [eclipselink.weaving] is incorrect when global instrumentation is null, value should either be null, false, or static.
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:174)
at javax.faces.component.UIInput.getValue(UIInput.java:291)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
(...)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
Any idea how to fix this lazy-loading issue? Why is the dynamic weaving not enabled by default ?
Thanks.
If you set eclipselink.weaving to true it means that you want to weave an entity classes dynamically. To make this work you need to run a jvm with a proper javaagent. First download an agent
wget -O /tmp/eclipselink.jar \
https://repo1.maven.org/maven2/org/eclipse/persistence/eclipselink/2.7.7/eclipselink-2.7.7.jar
and then run your app using following snippet
java -javaagent:/tmp/eclipselink.jar ....
But if you set eclipselink.weaving to static then you inform jpa that you want to weave the entity classes statically. Of course you have to trigger the waving by your own for example using this maven plugin https://github.com/craigday/eclipselink-staticweave-maven-plugin

OpenEJB + EclipseLink are not able to create tables on HSQL database

I have a vanilla maven WAR project, using the Java EE web profile, that executes its unit/integration tests using OpenEJB. During the OpenEJB start-up, instead of using the data source defined in jndi.properties, OpenEJB creates its own:
INFO - Auto-creating a Resource with id 'Default JDBC Database' of type 'DataSource for 'scmaccess-unit'.
INFO - Creating Resource(id=Default JDBC Database)
INFO - Configuring Service(id=Default Unmanaged JDBC Database, type=Resource, provider-id=Default Unmanaged JDBC Database)
INFO - Auto-creating a Resource with id 'Default Unmanaged JDBC Database' of type 'DataSource for 'scmaccess-unit'.
INFO - Creating Resource(id=Default Unmanaged JDBC Database)
INFO - Adjusting PersistenceUnit scmaccess-unit <jta-data-source> to Resource ID 'Default JDBC Database' from 'jdbc/scmaccess'
INFO - Adjusting PersistenceUnit scmaccess-unit <non-jta-data-source> to Resource ID 'Default Unmanaged JDBC Database' from 'null'
And then, further below, when it's time to create the table - as per the create-drop strategy defined on the app's persistence.xml file - I see several errors like this:
(...) Internal Exception: java.sql.SQLSyntaxErrorException: type not found or user lacks privilege: NUMBER
Error Code: -5509
The jndi.properties file:
##
# Context factory to use during tests
##
java.naming.factory.initial=org.apache.openejb.client.LocalInitialContextFactory
##
# The DataSource to use for testing
##
scmDatabase=new://Resource?type=DataSource
scmDatabase.JdbcDriver=org.hsqldb.jdbcDriver
scmDatabase.JdbcUrl=jdbc:hsqldb:mem:scmaccess
##
# Override persistence unit properties
##
scmaccess-unit.eclipselink.jdbc.batch-writing=JDBC
scmaccess-unit.eclipselink.target-database=Auto
scmaccess-unit.eclipselink.ddl-generation=drop-and-create-tables
scmaccess-unit.eclipselink.ddl-generation.output-mode=database
And, the test case:
public class PersistenceTest extends TestCase {
#EJB
private GroupManager ejb;
#Resource
private UserTransaction transaction;
#PersistenceContext
private EntityManager emanager;
public void setUp() throws Exception {
EJBContainer.createEJBContainer().getContext().bind("inject", this);
}
public void test() throws Exception {
transaction.begin();
try {
Group g = new Group("Saas Automation");
emanager.persist(g);
} finally {
transaction.commit();
}
}
}
Looks like eclipselink is trying to create a column with the type NUMBER and that type does not exist in HSQL. Did you specify that type in your mappings? If yes then fix that.
Otherwise it might help to add
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.create-ddl-jdbc-file-name" value="createDDL_ddlGeneration.jdbc"/>
<property name="eclipselink.drop-ddl-jdbc-file-name" value="dropDDL_ddlGeneration.jdbc"/>
<property name="eclipselink.ddl-generation.output-mode" value="both"/>
to your persistence.xml so you can see what create table statements are exactly generated. If eclipselink is using NUMBER on it's own for certain columns you can tell it to use something else by using the following annotations on the corresponding fields.
#Column(columnDefinition="NUMERIC")

JPA: Modelling a Map<Entity, Entity>

I am running into an exception when generating the database tables with EclipseLink for the following model:
#Entity
#Table(name="RXRACTSPOT")
public class ActivitySpot implements Serializable,IsSerializable {
.....
#OneToMany
private Map<CustomAttributeDefinition, CustomAttributeRestriction> customAttributes;
--
#Entity
#Table(name="RXRCUSTATTRREST")
public class CustomAttributeRestriction implements Serializable
--
#Entity
#Table(name="RXRCUSTATTRDEF")
public class CustomAttributeDefinition implements Serializable
I encounter the following exception:
Exception in thread "main" javax.persistence.PersistenceException: Exception >[EclipseLink-0] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
Exception [EclipseLink-93] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [RXRCUSTATTRREST] is not present in this descriptor.
Descriptor: RelationalDescriptor(com.rubiconred.activitystream.core.model.ActivitySpot --> [DatabaseTable(RXRACTSPOT)])
Runtime Exceptions:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:417)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:164)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:221)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:209)
at com.rubiconred.activitystream.database.ActivityStreamDatabaseUtils.dropAndCreateTables(ActivityStreamDatabaseUtils.java:64)
at com.rubiconred.soauiext.server.db.CreateOneSpotDatabases.main(CreateOneSpotDatabases.java:16)
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.IntegrityException
If I remove the Map in RXRACTSPOT then the tables RXRCUSTATTREST and RXRCUSTATTRDEF are successfully created. With the Map neither table is created and the exception is thrown. I suspect I am missing some annotation on the Map but I have been unable to find an example for a Map with both key and value as Entities.
Seems like a bug. Try the latest release, if it still occurs please log a bug.
You could also create another Entity class to represent the three way join table instead of using a Map.

OpenJPA Is Not Able To Create/Insert Table In Postgres DB

To get more familiar with the new Java EE 6 System I have created a little demo application that should be able to store some user input in a postgres database.
I am using:
- glassfish 3.1
- Postgres 9.1
- OpenJPA 2.1.1
For this purpose I wrote following entity:
#Entity
public class User implements Serializable
{
#Id
#GeneratedValue(generator="user_seq",strategy=GenerationType.SEQUENCE)
#SequenceGenerator(name="user_seq", sequenceName="user_seq",allocationSize=1)
public Long id;
The database is completely empty and the connection pool is configured in glassfish. My persistence.xml looks like this:
<persistence-unit name="myDatabase" transaction-type="JTA" >
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>jdbc/myDatabase</jta-data-source>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" />
<property name="openjpa.jdbc.DBDictionary" value="postgres" />
</properties>
</persistence-unit>
Due to the fact, that I dont want to insert all db-objects myself, I activated the automatic schema creation in my jpa properties. With the first start openjpa (or maybe postgre) creates a new sequence named 'user_seq' as mentioned in the annotations of the entity.
This works fine. But then openjpa wants to create the table 'user' and throws following exception:
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException:
FEHLER: Syntaxfehler bei »User«
Position: 14 {stmnt 31631786 CREATE TABLE User
(id BIGINT NOT NULL, userlastlogin VARCHAR(255), username VARCHAR(255),
userpassword VARCHAR(255), PRIMARY KEY (id))} [code=0, state=42601]
The SQL-Statement seems to be fine. If I create the table 'user' myself, I get the ReportingSQLException that openjpa is not able to insert the entity in the existing table.
First I thought that openjpa and postgre both wants to create the sequence with activated schema-creation. So changed the property to:
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(Sequences=false)" />
Unfortunately this did not work either.
What else can I say.. Hm.. My DAO looks like this:
#Stateless
public class DAOService
{
#PersistenceContext
protected EntityManager em;
public <T> T create(T t)
{
this.em.persist(t);
this.em.flush();
this.em.refresh(t);
return t;
}
Thanks for your help.
Perhaps 'User' is a reserved keyword on postgres? Can you try specifying the name of your Entity to be User0 or something?