jpa-2.0

How do I delete all JPA entities?

Hello, In my testing code I need to have a blank/empty database at each method. Is there code that would achieve that, to call in the @Before of the test? ...

How to write DDL in the criteria API?

Consider the code in http://stackoverflow.com/questions/3333308/how-do-i-delete-all-jpa-entities The documentation here http://download.oracle.com/docs/cd/E17410_01/javaee/6/tutorial/doc/gjitv.html describes only queries. ...

Why my equals method won't work?

assertEquals(def.getMengs(), exp.getMengs()); fails, reporting: expected: java.util.HashSet<[...so geht die Legende ... ...legend has it ... ]> but was: java.util.HashSet<[...so geht die Legende ... ...legend has it ... ]> Indeed, through the debugger I see that both sets contain only one Meaning with objId = 1 for both. I expected th...

Setting subclass primary key as auto_increment using JPA 2 annotations

Hi. I'm trying to generate a database schema for my project using hbm2ddl. I'm using JPA 2 annotations to specify how the schema should look like. Right now I'm having some issues with inherited id's. I have an abstract super class, let's call it AbstractSuperClass, which looks like this: @Entity @Inheritance(strategy=InheritanceType....

How to verify whether a record with certain field values exists in a DB with JPA?

How to express the exists clause with JPA? ...

Is there a tool that converts from JPQL into Criteria API?

Input: valid jpql output: java code using criteria api to achieve same jpql effects. ...

JPA 2.0 metamodel in Netbeans?

I've read that since version 6.9, Netbeans includes annotation processing support, a feature needed, for instance, to generate JPA 2.0 entities' metamodels. However, I couldn't find any examples or documentation that shows exactly how to do it. Have any of you guys succeed on this? ...

JPA createNamedQuery syntax

Hello, In Pro JPA 2 (Apress) book, I have seen examples like, EntityManager em; Long count = em.createNamedQuery(countQueryName, Long.class).getSingleResult(); But, the api , hopefully applied to JPA 2.0, shows the syntax as createNamedQuery(String name) Parameters: name - the name of a query defined in metadata with a single p...

JPA 2.0 Criteria and grouping of Predicates

I encounter problem with Hibernate EntityManager 3.5.3-Final when it comes to composite predicates. Example (not actual code snippet, but the idea should be clear): CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); Predicate predicate1 = criteriaBuilder.conjunction(); Predicate predicate2 = criteriaBuilder.conjuncti...

Hibernate JPA, MySQL and TinyInt(1) for Boolean instead of bit or char

Hi Here is my JPA2 / Hibernate definition: Code: @Column(nullable = false) private boolean enabled; In MySql this column is resolved to a bit(1) datatype - which does not work for me. For legacy issues I need to map the boolean to a tinyint not to a bit. But I do not see a possibility to change the default datatype. Is there any? ...

Storing a Map<String,String> using JPA

I am wondering if it is possible using annotations to persist the attributes map in the following class using JPA2 public class Example { long id; // .... Map<String, String> attributes = new HashMap<String, String>(); // .... } As we already have a pre existing production database, so ideally the values of attributes ...

How to catch a runtime exception in a NB platform module?

As described here, I want to update the user's database by means of catching the exception that occurs when the entity classes don't match. I understand that I could add a catch statement to every db-interface method, but that's error-prone*. Other 'polling methods' are also possible, but they are not interrupt-driven as I want through ...

JPA: When to choose Multivalued Association vs. Element Collection Mapping

I would like to better understand the differences between (1) a traditional Multivalued Relationship/Association @Entity -> @OneToMany -> @Entity and (2) the JPA2 Collection of Embeddable (and basic) Types @Entity -> @ElementCollection -> @Embeddable I see the syntactical differences, but wonder whether there are also ...

What are some of the real world example where JPA2 Criteria API is more preferable?

Hi all, I have taken a look at JPA 2.0 Criteria API, but I found it to be too cumbersome unlike Hibernate Criteria. Is there any good reason to use JPA 2.0 Criteria API rather than using JPA-QL? Thanks for your advise. ...

JPA Criteria API - How to add JOIN clause (as general sentence as possible)

I am trying to construct queries dynamically, and my next target is add JOIN clauses (I don't know how can I use the API). By now, for example, this code work for me : ... Class baseClass; ... CriteriaBuilder cb = JpaHandle.get().getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(this.baseClass); Root entity_ = cq.from(this.bas...

How to deal with database initialization?

As also described here, I'm trying to determine the best way to initialize and update my application's database. I use EclipseLink-JPA2. I distribute a NetBeans platform application. Considered options: use create-tables ddl-generation: The problem with this is that everytime the application runs it will throw exceptions, failing to c...

How to specify a jdbc.url in the persistence.xml relative to the application folder?

Once I deploy my application with JPA the user chooses to install it somewhere. Then however the property set as: <property name="javax.persistence.jdbc.url" value="jdbc:derby:db;create=true"/> gets interpreted into the following exception: couldn't create database in \db. Throughout development it used to be the relative path to the ...

EclipseLink: Checking current transaction isolation level

I have a standalone Java application that uses EclipseLink 2.0.1. It is configured by a persistence.xml, and then does something like: final EntityManagerFactory emf = Persistence.createEntityManagerFactory("xy"); final EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); .... em.getTransaction().commit(); I want...

Any drawbacks of using Hibernate EntityManager (vs. Hibernate Core)?

The Hibernate EntityManager documentation states, that: You may use a combination of all three together, annotations without JPA programming interfaces and lifecycle, or even pure native Hibernate Core, depending on the business and technical needs of your project. You can at all times fall back to Hibernate native APIs, ...

How do i use JPA 2 to connect to multiple data sources?

I have two databases in MSSQL ,and i want to connect to them using JPA2 I have managed to get it working with one . Can some one help me how do i do that? Thanks a Lot. ...