jpa

Positional Parameter with IN clause in JPA

I'm trying to evaluate the following JPQL query: select err from Error err where err.errType = ? and err.msg in (?) The err.msg is a relationship to an Object derived from a class called CSMessage. So I do something like this: ...fetch my CSMessage from the DB. This part actually works... List<CSMessage> msgList = new ArrayList<CSM...

JPA - How to truncate tables between unit tests

I want to cleanup the database after every test case without rolling back the transaction. I have tried DBUnit's DatabaseOperation.DELETE_ALL, but it does not work if a deletion violates a foreign key constraint. I know that I can disable foreign key checks, but that would also disable the checks for the tests (which I want to prevent). ...

Object: mypackage.Report[id=null] is not a known entity type (JPA persistence)

I am using netbeans to create a simple java app using persistence, and I can query my Entitys using ReportJpaController rjc = new ReportJpaController(); Report report = new Report(name,value,timestamp); List<Report> reports = rjc.findReportEntities(); rjc.create(report); but when I try to call create I get the following err...

How can read-only collections be mapped in JPA / Hibernate that don't cause DB updates.

Hi all, is it possible to create relations in hibernate / jpa that are fetched when the containing entity is fetched but will never ever result in any db updates, when the containing entity is saved? I'll try to make the requirement clear by an example. I have a simple entity B @Entity public class B { private int bId; @Id ...

EclipseLink: don't fetch some fields by default

Let's say we have an entity @Entity public class Person { @Id int id; @Basic String name; @Basic String remark; } Let's say "remark" field is filled with big texts, but rarely used. So it would be good if when you run jpql: SELECT p FROM Person p, EclipseLink just executes sql select id, name from person And than when you...

JPA (Hibernate) - Session/Transaction and lazy loading

Hello! I have a Java EE project and the MySQL database is managed with an ORM. I worked a lot with Hibernate to learn what I am doing wrong and I think I understand session/transaction, but I do not know how I can solve this in my case/architecture. I have a Project and a Person which are in a bi-directional n:m relation with a join ta...

EclipseLink/JPA: Multiple @DiscriminatorColumn annotations for Entity

I'm looking for a way in EclipseLink to have two @DiscriminatorColumns on the same entity My PostreSQL DB table is: Dictionary { id, object_type, attribute_type, translation } And classes are: @Entity @Table(name = "dictionary") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="object_type", ...

How to externalize properties from JPAs persistence.xml?

I would like to put some of the hibernate configuration in a property file to make it editable without build and deploy. I tried to solve my problem by following the instructions from http://stackoverflow.com/questions/1989672/create-entity-manager-without-persistence-xml app.properties: hibernate.show_sql=true hibernate.dialect=org...

JPQL: How to include Forward Slash in Query String?

How do you properly escape a '/' forward slash in a JPQL query string? If I do this: LOCATE('/', REVERSE( ... I get: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query However, if I do this: LOCATE('\\', REVERSE( ... Everything is fine. So, how do I include the forward...

How do you set the schema name for sequences at deploy time when using JPA?

For security reasons, our oracle db objects normally belong to a different schema than the logged in user. Eg. tables are in xx_core and the user we log in is xx_app_yy . In my persistence.xml I define a orm file so that I can specify the schema name at deploy time eg.: <mapping-file>xx_schema_orm.xml</mapping-file> Then in the xx_s...

problem with using JPA

I am getting following error while executing a unti test case(JUNIT).I am using it to understand the part of the project.Project is a web based project.Project is using OPENJPA <openjpa-1.2.1-SNAPSHOT-r422266:686069 fatal store error> org.apache.openjpa.persistence.RollbackException: Unable to obtain a TransactionManager using null. ...

Searching in a collection with JPA/Hibernate

Hi, I would like to make a query from an object I have defined that contains a collection. Object looks like this: @Entity public class ValidationLog { @Embeddable public static class ValidationLogPK implements Serializable { private String dataKey; @Enumerated(EnumType.STRING) private DataType dataType;...

JPA / Hibernate - ConstraintViolationException by removing an element

Hello! I have a JPA/Hibernate problem with a n:m relation (Project <-> Person) with a join table. The Project is the mapping owner and has a (cascade = CascadeType.ALL). Now I want to remove a project which is associated with a Person, so there is an entry in the Project_Person join table, but I get a org.hibernate.exception.Constrai...

How can I retrieve the foreign key from a JPA ManyToOne mapping without hitting the target table?

I have the following two annotated classes that I use to build a graph: @Entity @Table(name = "Edge") public class Edge { /* some code omitted for brevity */ @ManyToOne @JoinColumn(name = "ixNodeFrom", nullable = false) private Node _nodFrom; @ManyToOne @JoinColumn(name = "ixNodeTo", nullable = false) ...

Create database with JPA ??

When I create (using JPA - java persistence api) a persistence unit and then persistence entities they auto create the corresponding tables and fields in the database. Can I also make it to auto create the database (if it doesn't exist)? My objectif is : I mean it creates inside the database the tables and fields, but not the databas...

How to implement generics using JPA/hibernate EntityManager and EJB3.0 ?

I have an slsb holding my business logic, how do I use generics to change the following three methods into one generic method ? The first two are the same db, the third is a different database. Also do the methods require further annotation in relation to transaction ? @PersistenceContext(unitName = "db") private EntityManager myEntity...

Forms in Lift with JPA models

Hi, there is .toForm in every Mapper field. How do you do this (create forms from models) in JPA models? Thanks in advance, Etam. ...

C3p0 connection pooling for jpa in persistence.xml not working?

I'm still getting JDBC timeouts after trying to configure c3p0 following all of the examples I could find. I'm using JPA, Hibernate, Tomcat, MySQL [AWS RDS]. Here's the snippet from persistence.xml: <property name="javax.persistence.jdbc.url" value="jdbc:mysql://url..." /> <property name="javax.persistence.jdbc.driver" value="com.mysql....

Best practice: best database naming convention for JPA?

In Java the naming convention for properties en classes (entities) are done the CamelCase way: @Entity public class UserMessage implements Serializable { @Id private Integer id; private String shortTitle; private String longTitle; private String htmlMessage; } But in the SQL world it’s considered a best pract...

JPA XML Query File

Hi! I would like to include all named queries in a separate XML file and use it in persistence. How can I accomplish the same? I am using Toplink JPA in a JSF-Web application. Actually I am not able to get the directory/file structure to use. I tried to use in persistence.xml and tried to place the query file in several locations. Eve...