jpa

ClassLoader getResources doesn't find all versions of the file

We have a issue where we are trying to merge persistence.xml files from multiple JAR's Thread.currentThread().getContextClassLoader().getResources(PERSISTENCE_XML) Does return a list of all persistenc.xml files from all projects, however when we make JAR files of each project, classloader.getResources(PERSISTENCE_XML) no longer return...

EntityManager not fetching from database?

Hello, I have entities: Post, User, Comment with bidirectional relationships: --------- 1 * --------- | Post | <--------> |Comment| --------- --------- --------- 1 * --------- | User | <--------> |Comment| --------- --------- I have simple page which displays single post and all its comments and...

Hibernate : Foreign key has the wrong number of column. should be 0

Hi , I am trying to evaluate a mapping in this Hibernate document : section 2.2.3.1. Generating the identifier property http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-identifier In the document , Person and MedicalHistory has @OneToOne mapping (MedicalHistory points to Person) , and the do...

JPA/Hibernate mapping dynamic columns as a List of objects

I have an existing DB schema which I'm trying to ORM'ise with JPA/Hibernate annotations. The schema is designed to allow for clients to assoicate extra information with each row in a table. Rather than using a key-value pattern the existing solution determines the required number of dynamic columns at install time, and alters the table t...

JPA/EclipseLink - Retrieve Columns Names

Hi, I'm trying to update my knowledge in Java, since I last used in when it was in 1.4.X version... I'm trying to use 1.6.0, in particular the Java Persistence API (2.0). I managed to create an entity class. It's working, since I'm able to store and retrieve data. But I was fooling around and when I decided to fill a JList with the co...

Convert JQL to CriteriaBuilder

OK.. I'm stuck. Can someone help me converting this JQL SELECT a FROM Asset a WHERE ?1 IN (SELECT c FROM a.categories c) categories is a collection of Enum. I have difficulty converting the WHERE part. I don't understand why method CriteriaBuilder.IN only receive one value. Anyone can help me? ...

Hibernate & EhCache: net.sf.ehcache.Statistics not populated?

I think my Hibernate (3.5.3) Second Level Cache is well configured with EhCache (2.2). At least, I observe following log entries: 20:15:28 DEBUG [net.sf.ehcache.Cache#searchInStoreWithStats] persistence.unit:unitName=#pu-pay.c.u.p.model.ActionCache: persistence.unit:unitName=#pu-pay.c.u.p.model.Action store hit for c.u.p.model.Action#T...

JPA Query optimization by avoiding JOIN to lookup table?...

Imagine a table emp: CREATE TABLE emp ( id NUMBER , name VARCHAR , dept_code VARCHAR ) and a table dept: CREATE TABLE dept ( code VARCHAR , name VARCHAR ) emp.dept_code references dept.code as a ForeignKey. These tables are mapped to JPA Entities, and the ForeignKey is modeled as an association...

How to use JPA2's @Cacheable instead of Hibernate's @Cache

Typically , I use Hibernate's @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) to cache an @Entity class , and it works well. In JPA2 , there's another @Cacheable annotation that seems to be the same functionality with Hibernate's @Cache. To make my entity class independent of hibernate's package , I want to give it a try....

Add Property to javax.peristence Entity

I right click into the editor of the Entity class. then select Insert Code but do not see the Add Property box. I want to add a birthday property which must be annotated with the javax.persistence.Temporal annotation to mark the property as date field to the underlying database table. I am unsure how to use the Netbeans 6.8 IDE to add ...

Strange hibernate exception when running under Linux

I have a project that compiles and runs completely fine under OS/X, but under Linux an exception is thrown that gives no clue as to what might be the problem. I've been stuck on this for hours trying to narrow it down, any pointers would be helpful! java.lang.ExceptionInInitializerError at java.lang.Class.forName0(Native Method) ...

How to change JPA 2.0 SQL/JPQL queries dynamically in production

Hello! I have a problem with the architecture of JPA 2.0/ORM, in our production system (and i believe in a lot of systems) we need the ability to change the SQL queries dynamically because slow queries and bugs in queries that was exposed only in production (heavy load and heavy data), as a result we used in stored procedures and call t...

Simple jpa question

I have to go through some code of a project to implement some missiong functionality. It uses jpa.In some popj classes i have found @Entity @Table(name="TYPE") @NamedQueries( { @NamedQuery(name = "getTypes", query = "SELECT dct FROM Type dct") }) I know that i can used to get all records by using this query.Does this query return ...

JPQL LIKE expression on enum

Can JPQL execute LIKE expressions against enums? If I have an entity Foo with an enum field bar I can execute the following in MySQL(bar is stored as a MySQL enum)... SELECT * FROM Foo WHERE `bar` LIKE '%SUFFIX' However, the corresponding query in JPQL... SELECT f FROM Foo f WHERE f.bar LIKE '%SUFFIX' ...complains that... Param...

REST and JAVA JPA

I am trying to understand the code of some project which is not properly documented.Am the only developer working on the task.I dont have much experience. There is a data model and there are some classes witten to access it.It was mentioned that the data model has some rest api on top of it.But when i see the code i can see getter cod...

Problem in saving List<String> through JPA?

I have already seen http://stackoverflow.com/questions/287201/how-to-persist-a-property-of-type-liststringin-jpa and http://stackoverflow.com/questions/796347/map-a-list-of-strings-with-jpa-hibernate-annotations ============================================================================= I am trying to save List<String> throu...

JPA Query MONTH/YEAR functions

How can I write a JPA query using MONTH function just like sql query? @NamedQuery(name="querybymonth", query="select t from table1 t where MONTH(c_Date) = 5") When I use the above pattern for query, I get an error: unexpected token - MONTH. ...

jpa 2 hibernate setting a lock on EntityManager.find

Hi guys: a little strange problem.. I'm doing a few testcases on an hibernate project: when I call EntityManager em = getEntityManager(); em.find(Foo.class, 1) I get the entity as I expect, but when I invoke: EntityManager em = getEntityManager(); em.find(Foo.class, 1, LockModeType.WRITE) I'm getting null. Also, w...

Calling Oracle functions from EJB in Seam framework

Hi, I am using seam framework and struggling to call a Oracle function. In my EJB, I am creating a namedQuery and when I call my entityManager.getResult() I get the following error: PLS-00222: no function with name 'jjhg' exists in the scope. (jjhg is the name of my oracle function) Please help. This is a bit urgent for me ...

How should I reset a JPA-controlled database before every test?

Is there a best-practice pattern for completely resetting a database to a freshly-paved schema with JPA before a unit test? I have been using a testing persistence unit with hbml2ddl.auto=create-or-drop and recreating EMFs before each test, but I wonder if there's a cleaner way to do it. ...