FAQ Database Discussion Community


JPA The state field path cannot be resolved to a valid type

jpa,eclipselink
I need assistance in troubleshooting a relationship / query with EclipseLink 2.5.x provider. The relationship from ThreePhaseMotorInput to ValidationMessage is supposed to be a uni-directional OneToMany, i.e. each motor can have 0..n messages and in Java object graph ValidationMessage does not have a reference back to ThreePhaseMotorInput. I am getting...

JPA Not Maintaining Connections

java,jpa,eclipselink
So it looks like once the program ends, the object connections aren't persisted. Let me explain with a simple example: //Adding a friend to person and "sending" that friend a message. em.getTransaction().begin(); Friend person = new Friend(); person.setName("One"); Friend friend = new Friend(); friend.settName("Two"); Message messageToFriend = new Message(); messageToFriend.setMessage("Hi");...

jpa cascading deletes reverse relationship

java,jpa,delete,eclipselink,cascading
Dear experts and colleagues, My question is about cascading deletes with JPA and Eclipselink. I would like to model a simple relationship between two entities: A and B. B references A through a property ref2a (in DB terms B.ref2a is connected to A.id through a foreign key with "ON DELETE...

How to initialize EclipseLink connection

jpa,eclipselink
Sorry if my question is quite simple, but I really couldn't find an answer googling. I have this project with JPA 2.0 (EclipseLink), it's working fine but I want to ask if there's a way to initialize the database connection? Actually it begins whenever the user try to access any...

Does EclipseLink DescriptorCustomizer not support inherited subtypes?

java,jpa,eclipselink
Basically, I have a base class type that describes entities as being not deletable. I use eclipse link's descriptor customizer API to override the default delete SQL and add an additional criteria to only return non-archived entities. This works for all classes that extend the Archiveable class directly. Classes that...

JPA persistence updates

mysql,java-ee,jpa,eclipselink
EclipseLink 2.5.2, NetBeans 8.0.2, Java 8, Derby: I have a DB structure with sort of a tree hierarchy and cross references using foreign keys. As an example it has the following key relationships T1 is the parent. T2, T3 & T4 are children of T1. T5 is a child of...

RCP Editor and JPA merge

eclipse,jpa,eclipse-rcp,eclipselink,jpa-2.1
I am updating an RCP based application to use JPA 2.1 (EclipseLink's implementation) from Hibernate 3.x. The JPA merge behavior is causing me problems. The issue I am seeing is when I assign the returned value to the model object in the RCP editor (inherited from FormEditor) it is a...

Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00972: identifier is too long

jpa,ejb,eclipselink
i develop an application with swing i habe a database with few tables; these Tables are connected with foreign key When I try to run this application , i have the error; Exception in thread "AWT-EventQueue-0" javax.ejb.EJBException: EJB Exception: ; nested exception is: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.2.v20130514-5956486):...

EclipseLink JPA - @OneToMany / @ManyToOne

jpa,eclipselink
I am using Java 8, EE7, NetBeans 8.0.2, EclipseLink 2.5.2 & Derby Originally my entity classes were created for me by NetBeans which probably defaults to defining both sides of a relationship when foreign keys are involved. Recently I did a bunch of research to understand this better and have...

EclipseLink JTA Persistence issue (Null Pointer Exception)

java,mysql,jpa,eclipselink,jta
I have two entities working in Mater Detail pattern like i describe in: Stackoverflow Post: jpa-eclipselink-onetomany-derived-ids-fail The pattern works as expected with LOCAL RESOURCE, but when i try to move the example to a web environment GlassFish4.1 (JSF) with JTA, i get the following error: Advertencia: DTX5014: Caught exception in...

Check if JPA entity exists without loading it

java,jpa,persistence,eclipselink
The problem is following. We have a server endpoint, that receives feedback from clients. Feedback received in multipart/form-based format, with fields: ProductId - product identifier Message - feedback message Log_file - attached log file Screenshot - attached screenshot file Server code first checks if the product with given id exists...

JPA select ignoring OR part

java,mysql,jpa,select,eclipselink
I have select query: SELECT entity FROM EnterpriseEventLog entity WHERE entity.enterprise.recordId = :recordIdEnterprise OR entity.group.enterprise.recordId = :recordIdEnterprise But part "entity.enterprise.recordId = :recordIdEnterprise" is ignored by JPA, select works like there is no such part. If I delete this "OR entity.group.enterprise.recordId = :recordIdEnterprise" select works correctly and extracts data. I use...

JPA: Using @MapKey for an abstract class

java,hibernate,jpa,eclipselink,jpa-2.0
I have the following structure of an abstract superclass A and a class Z referring to As sublasses B and C using a map: @Entity Abstract Class A @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; Integer map_field; <----------------------- Problematic .... @Entity Class B extends A @Id @GeneratedValue(strategy = GenerationType.AUTO) private...

String list identity in where clause of JPA / JPQL Query

java,java-ee,jpa,eclipselink,jpql
Say I have an @Entity like class C { List<String> sequence; } and I want to query for instances of C that exactly match a given list. (I am aware that this is order sensitive, and I'm ok with that.) I am using EclipseLink and query with JPQL. I tried...

JPA EclipseLink oneToMany Derived Ids Fail

mysql,jpa,eclipselink,foreign-key-relationship
Hello I'm trying to make an example of persistence of a OneToMany relationship in which I get the following error: Exception Description: Invalid composite primary key specification. The names of the primary key fields or properties in the primary key class [entitys.OrderItemPK] and those of the entity bean class [class...

Jpa Persist primary key restriction violation

java,jpa,eclipselink
I'm having some problem on transitive persistence. Now I try to describe my problem in a more detailed way. I have two entities Row and Field. @Entity public class Row implements Serializable { private static final long serialVersionUID = 1L; @Id @SequenceGenerator(name="ROW_IMPORT_ID_GENERATOR", sequenceName="SEQ_RIGA_IMPORT") @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="ROW_IMPORT_ID_GENERATOR") private Long id; //bi-directional many-to-one...

When NOT to use EntityManager.flush()?

java,jpa,eclipselink,entitymanager,flush
For synchronization and to retrieve the DB-generated ID's I feel coerced to call EntityManager.flush() at several places. Performance implications aside, are there reasons not to call flush()? In other words, is there any observable difference for the caller of my (DAO, ...) method if it does/doesn't flush()? My scenario is...

NullPointerException in EclipseLink initialization

java,jpa,eclipselink
I am using Eclipselink 2.6.0-RC2 from maven repository and trying on the inheritance. I have the 3 classes below: @Entity @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name = "CLASSNAME") public abstract class Project { @Id @Column(length = 50) private String id; } @Entity @DiscriminatorValue(value = "Foo") public class FooProject extends...

Don't changed data on jsp after update data in postgresql

postgresql,jsp,servlets,jpa,eclipselink
I have class to get data from db and servlet for send this data to jsp. If i insert or delete row in the table (using pgAdmin), data on jsp is updated (with new data), but if i update existing date in table, it's not updated on the jsp (only...

Incrementing a sequence by 1000 each persist of a new Entity

oracle,jpa,eclipselink
We have some jdbc legacy code we are converting to JPA, we used to get ids from oracle using SELECT business_object_seq.nextval FROM dual; with the sequence specified as CREATE SEQUENCE business_object_seq INCREMENT BY 1000 START WITH X; with X being an integer less than 1000 matching the node id of...

javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on event:'prePersist'

hibernate,jpa,eclipselink,bean-validation,jsr303
Given two entities Department and Employee forming a unidirectional one-to-many relationship from Department to Employee based on respective tables in the database in question as follows. public class Department implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "department_id", nullable = false) private Long departmentId; @Size(max =...

Entity class must have non argumented constructor

java,hibernate,jpa,eclipselink,entitymanager
I am studying JPA, so while studying on a JPA BLOG Vogella 1.2 Entity Heading, i came across a line which says: All entity classes must define a primary key, must have a non-arg constructor and or not allowed to be final I am not able to understand this line....

Lucene integration with EclipseLink

java,lucene,eclipselink
I am trying to use Lucene with EclipseLink, and was wondering if there are any good integration libraries out there? I have seen solar-flare, and it looks lime it might do what I want, but it's out of date (although i have an older version of EclipseLink, I am using...

JPA ERROR: relation does not exist

java,postgresql,jpa,runtime-error,eclipselink
I can't figure out what I'm doing wrong. I'm learning JPA mapping to a relational DB, by following some tutorials on the web, but can't find one that is straightforward. When I run my project, it gives me an error. I guess it's upon persisting em.persist();. If I comment that...

eclipselink condition on class type in ReportQuery

java,eclipselink
Assume I have two entities ChildClassA e ChildClassB that inherits from class MySuperClass: @Entity @Table(name = "MY_TAB") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "MY_DISC") public class MySuperClass { @Column private String X; @Column private String Y; ... } @Entity @DiscriminatorValue(value = "A") public class ChildClassA extends MySuperClass { ... } @Entity...

How to load the actual Hibernate entity association and not the LAZY proxy

java,hibernate,jpa,proxy,eclipselink
I'm coming from eclipselink and try to work myself through Hibernate. Lets assume we have a class Car and a class Wheel. The Car class has n wheels. Both entities are connected with a bidirectional association. More importantly on the Wheel side I have a Car reference: @ManyToOne(fetch = FetchType.LAZY)...

Changing JPA (EclipseLink) Java serialization to using Jackson / json

java,jpa,serialization,eclipselink
I'm interested in replacing the default java serialization in EclipseLink JPA to json using the Jackson engine. Is there a property where I can set the serialization engine for all my setup? I know EclipseLink support serialization of json with MOXY but I have other issues with using it. I'm...

java.lang.NoSuchMethodError: org.springframework.beans.BeanUtils.findPropertyForMethod

eclipselink,spring-data,spring-data-jpa
I am getting below error while trying to configure spring data in my applciation. I am using spring data and EclipseLink, along with spring-security and oauth2. SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener java.lang.NoSuchMethodError: org.springframework.beans.BeanUtils.findPropertyForMethod(Ljava/lang/reflect/Method;Ljava/lang/Class;)Ljava/beans/PropertyDescriptor; at...

JPA (EclipseLink) returning null in list

java,jpa,eclipselink
I didn't know if it was appropriate to delete the original question but have added a more concise explanation at the bottom hopefully eliminating the need to review all of the details. I am receiving inconsistent results and can't figure out what I am doing wrong. It relates to an...

EclipseLink Query - Select count(*) from student s not working

java,sql,postgresql,jpa,eclipselink
I am getting following exception :- [13, 13] The left expression is missing from the arithmetic expression. [14, 14] The right expression is missing from the arithmetic expression. Please help me analyse the problem. P.S. If I replace the above query in my code with select * from student s,...

JPA Entities from Tables turns int primary key to String

java,mysql,hibernate,jpa,eclipselink
I use Eclipse --> JPA Entities from Tables get generate entities from mysql database. All the tables' primary keys -- ids are int(11) AI PK. So instead of int or long, i am getting String for all the keys. What did i do wrong? Thanks! @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name="LOCATION_ID") private String...

JPA: Using composite primary keys for map relations

hibernate,java-ee,jpa,eclipselink
Following an relation mapping example for Maps, I have EMPLOYEE ID FIRSTNAME LASTNAME SALARY 1 Bob Way 50000 2 Sarah Smith 60000 PHONE ID OWNER_ID PHONE_TYPE AREACODE NUMBER 1 1 home 613 792-7777 2 1 cell 613 798-6666 3 2 home 416 792-9999 4 2 fax 416 798-5555 Example of...

EclipseLink JPA: list entities with reference variables

java,jpa,eclipselink,entitymanager
I am using JPA's eclipseLink to perform CRUD operations on my entities. I am facing following problem: I have two tables in DB: CREATE TABLE User ( id INTEGER PRIMARY KEY AUTO_INCREMENT, username VARCHAR(30) NOT NULL UNIQUE, email VARCHAR(50) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, signUpDate timestamp NOT NULL...

Soft delete on many-to-many association EclipseLink

java,jpa,orm,many-to-many,eclipselink
I want to rewrite the call delete operation (on association table) on a many-to-many association sending by EclipseLink when we use only java code. Let me explain the goal. I have 3 tables, person, unit and an associative one : PerInUnit, so a person can be in multiple units and...

JPA in Java SE vs Java EE performance

java,java-ee,jpa,db2,eclipselink
I'm using JPA/Eclipselink in Java SE (Oracle Java 7) and Java EE (Websphere Liberty) environments. I have a component which is called from both Java SE and Java EE (by component I mean the same source code), which executes JPA queries. (the Java SE run is started with -javaagent:lib/eclipselink.jar param)...

EntityManager nested transaction atomicity

java,java-ee,jpa,transactions,eclipselink
In legacy code I solving problem with nested transactions. (Spring, CDI, etc cannot be used only pure JPA(EclipseLink)) em.getTransaction().begin(); em.persist(client); em2.getTransaction().begin(); em2.persist(client1); //saved into DB em2.getTransaction().commit(); em.getTransaction().rollback(); public void method(){ EntityManager em = entityManagerFactory.createEntityManager(); em.getTransaction().begin(); em.persist(client); nestedTransactionMethod(); em.getTransaction().rollback(); } public void nestedTransactionMethod(){...

Java JPA - Inner Join Query doesn't work

java,mysql,jpa,eclipselink
I'm currently having an issue using Java JPA with EclipseLink - this query: SELECT VAR_INPUT.* FROM VAR_INPUT INNER JOIN TYPE_VAR_INPUT ON VAR_INPUT.ID_TYPE_VAR_INPUT = TYPE_VAR_INPUT.ID_TYPE_VAR_INPUT WHERE TYPE_VAR_INPUT.IS_MANDATORY_TYPE_VAR_INPUT=true; is working fine when run directly on my database, but doesn't work when I use it with JPA. JPA Query: @NamedQuery(name = "VarInput.findAVarInputllOfMandatoryType", query...

Bidirectional relationships in JPA

hibernate,jpa,eclipselink,jpa-2.1,bidirectional-relation
I am missing something very fundamental. Given below two entities Department (inverse side) and Employee (owning side) forming a one-to-many relationship from Department to Employee. Department.java @Entity @Table(catalog = "testdb", schema = "", uniqueConstraints = { @UniqueConstraint(columnNames = {"department_id"})}) public class Department implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional...

use like for integer value in namedquery Eclipselink

java,jpa,eclipselink
when use namedQuery in entity class get error @NamedQuery(name = "Classification.search", query = "SELECT c FROM Classification c WHERE c.id LIKE :value") Method for call namedQuery public List<Classification> search(String value) { Query query = getEntityManager().createNamedQuery("Classification.search", Classification.getClass()).setParameter("value", "%"+value+"%"); query.setMaxResults(10); return query.getResultList(); } java.lang.IllegalArgumentException: You have attempted to set a value of...

There should be one non-read-only mapping defined for the primary key field

jpa,mapping,eclipselink
Hi I've the following code (using eclipselink 2.6): Transmission: @Entity public class Transmission { @Column(name="TRANSMISSION_ID") @Id private Long id; @Column(name="TRANSMISSION_CONTENT") private String content; .... } HeaderPk: @Embeddable public class HeaderPk { // this is a foreign key to "TRANSMISSION_ID" in Transmission @Column(name="FK_TRANSMISSION_ID") private Long transmissionId; @Column(name="MAILBOX_ID") private String mailboxId; @Column(name="TRANSMISSION_TIME")...

How readonly entity get persisted for the first time

java,jpa,eclipselink
if readonly entity cannot be persisted , how it is persisted for the first time. thinking in the matter lead me to three choice for the persist of readonly entity: readonly entity included in two type of mapping at which it is not readyonly in one of those type. readonly...

How to avoid persisting new object when oneToMany connection?

java,mysql,jpa,eclipselink,one-to-many
There is a three lines in returnreason-table and I don't want more lines there. User just choose one of the three reasons and I want only id to rma-table. Now it inserts a new line to reason-table every time when inserting new rma. I can take relation off between...

Cascade types in JPA

hibernate,jpa,eclipselink,cascade,jpa-2.1
Given two entities Department and Employee forming a one-to-many relationship from Department to Employee. Since the relationship is quite intuitive, I am leaving out the entity classes. In Department : @OneToMany(mappedBy = "department", fetch = FetchType.LAZY) private List<Employee> employeeList = new ArrayList<Employee>(0); In Employee : @ManyToOne(fetch = FetchType.LAZY) private Department...

Getting ClassNotFoundException org.eclipse.persistence.jpa.rs.resources.MetadataResource

java,jpa,glassfish,eclipselink,jpa-rs
I'm trying to walk through the JPA-RS tutorials like: http://java.dzone.com/articles/introducing-eclipselink-jpa-rs or http://www.eclipse.org/eclipselink/documentation/2.5/solutions/restful_jpa.htm But after trying to deploy (/w maven and glassfish plugin) the application on my glassfish I get the following error stacktrace: WebModule[/rest]Servlet /rest threw load() exception java.lang.ClassNotFoundException: org.eclipse.persistence.jpa.rs.resources.MetadataResource at...

OneToOne PrimaryKeyJoinColumn Cascade

hibernate,jpa,eclipselink,jpa-2.0
I am struggling a little bit to make Eclipselink to cascade persist a relationship: @Entity class Notification { @Id @UuidGenerator(name="UUID_GEN") @GeneratedValue(generator="UUID_GEN") @Column(name = "NOTIFICATION_ID") private UUID id; @OneToOne(cascade = ALL, fetch = FetchType.EAGER) @JoinFetch(JoinFetchType.INNER) @PrimaryKeyJoinColumn(name="NOTIFICATION_ID", referencedColumnName="NOTIFICATION_ID") private Notificator notificator; ... } @Entity class Notificator { @Id @Column(name="NOTIFICATION_ID") private UUID id;...

Modifying a large set of objects using JPA / EclipseLink

java,jpa,eclipselink
I need to iterate 50k objects and change some fields in them. I'm limited in memory so I don't want to bring all 50k objects into memory at once. I thought doing it with the following code using cursor, but I was wondering whether all the objects I've processes using...

EclipseLink doesn't recognize int(11) in MySQL

java,mysql,jpa,eclipselink
I know when I create a table with column data == int. I get something like int(11) as data type for this column. This somehow messes up my EclipseLink when auto generating Entities from Table. Eclipse doesn't understand int(11) as the data type so it converts everything to String instead...

static weaving eclipselink jpa with spring and tomcat

spring-mvc,jpa,tomcat7,eclipselink,compile-time-weaving
I am trying to achieve static weaving with Eclipselink+Spring+JPA using maven. I have configured my spring project with Java Configuration, no context.xml. I tried following things: In persistence.xml: Added following weaving specification. <property name="eclipselink.weaving" value="static" /> In DBConfig.java, I have configured beans as follow : @Bean() public DataSource getDataSource() {...

Exclude Field in Class from JPA

java,jpa,eclipselink
I have an entity in JPA. I recently added a field to my entity. I do not want this field to be persisted. However, Eclipselink is complaining about it not being in the table (which it obviously isnt). How can I exclude this class from be looked at by JPA....

Why is GenerationType.AUTO not using a serial on PostgreSQL?

java,postgresql,jpa,eclipselink,sequence
I have an application using JPA (with eclipselink). The application was developed with a Derby database in the background. The tables were generated by JPA itself. This is a simple example of one of the entities: public class MyEntity implements Serializable { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; @Column(nullable=false) private String...

JPA: Map multiple Oracle users on single persistence unit

java,spring,oracle,jpa,eclipselink
I am using EclipseLink 2.5.2 (JPA 2.1), Spring 4.1.5, and I am deploying on Weblogic 12 and Oracle 12c. I need to deploy my application to use 2 schemas (2 users on the same DB). The first contains the application data, the second contains lookup date which will never change....

Disable internal logging of MOXy (eclipselink)

java,eclipselink,moxy,persistence.xml
For a project I'm using MOXy in order to (un)marshal XML files, and I have some problem with it that I didn't have with the standard jaxb engine. But here, I'll focus on a single issue: I want to disable the internal logging of eclipselink. For example, I have logging...

Why is persist method called twice?

java,jpa,many-to-many,eclipselink
In my service level I create a new object from Entity1 class and persist it and then call setters on it. but after all, another object from Entity1 will be created and inserted in database( so I will have two rows in Entity1 table inserted in database instead of one)....

Can EclipseLink create the database specified in persistence.xml?

mysql,jpa,eclipselink
I'm working through the exercises in Beginning Java EE 7 except I'm trying to adapt them to use MySQL instead of Derby. For the chapter 4 JPA exercise, I changed the persistence.xml to this: <?xml version="1.0" encoding="UTF-8"?> <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="chapter04PU"...

Order By Oracle Function In JPA Criteria Builder

java,hibernate,java-ee,jpa,eclipselink
I have the following SQL SELECT ID,LASTTIMEEXECUTEDDATE as d FROM STATISTICSDATE ORDER BY LASTTIMEEXECUTEDDATE which using CriteriaBuilder works just fine: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<StatisticsDate> cq = cb.createQuery(StatisticsDate.class); Root<StatisticsDate> rootEntry = cq.from(StatisticsDate.class); CriteriaQuery<StatisticsDate> all = cq.select(rootEntry).orderBy(cb.desc( rootEntry.get("lastTimeExecutedDate"))); TypedQuery<StatisticsDate> allQuery = em.createQuery(all);...

JPA: persist a Map including the original “key” value

java,hibernate,java-ee,jpa,eclipselink
I need to store a complex tree-like object structure using JPA. There is a "top-level" class A on which I therefore can perform a CASCADE.ALL but I have a problem with a sub-object of Class B and a HashMap field. The "key" of the Map is a hashcode of the...

Eclipselink cache - preserving same object accross transactions

java,jpa,eclipselink
I'm working with Eclipselink as a JPA provider. The following code is used to access entities from the database: em.merge(anEntity); em.getTransaction().commit(); em.getTransaction().begin(); anEntity2 = em.find(targetClass, anEntity.getId()); Is there a way to guarantee that the object anEntity == anEntity2 will hold, that is always the same object reference is returned? For...

JPA left outer join using CriteriaBuilder results in error: Partial object queries are not allowed to maintain the cache or be edited

java,jpa,eclipselink,jpa-2.0,criteria-api
I have the following entity relationships Product @Entity @Table(name="PRODUCTS") public class Product @Id @Column(name="product_id") private long productId; @ManyToOne @JoinColumn(name="EMP_NUMBER") private Employee employee3; .... .... Employee @Entity @Table(name="EMPLOYEES") public class Employee @Id @Column(name="EMP_NUMBER") private String empNumber; @Column(name="EMP_NAME") private String employeeName; @OneToMany(mappedBy="employee3") private List<Product> Product3; .... .... In DAOImpl class I have...

Hiding foreign entity classes from EclipseLink

java,jpa,glassfish,eclipselink
I have a Java EE web application and a custom realm (authentication module) for Glassfish 4 (see GlassFish Application Development Guide, II 4-6 "Creating a Custom Realm"). Both of them are using JPA, with subtle differences. Custom realm <persistence-unit name="AuthPU" transaction-type="JTA"> <jta-data-source>jdbc/AuthDB</jta-data-source> <class>auth.User</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> </persistence-unit> auth.User is a technical entity...