jpa

Using HSQL in-memory database as JPA datasource

I have an in-memory data source: java.sql.Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:testdb", "sa", ""); emf = Persistence.createEntityManagerFactory("manager"); But now I'm stuck. I want to use it as a JPA data source in a J2SE application. I've scoured the entire web but all info is related to J2EE. <pe...

How to generate ORM.XML mapping files from annotations?

At work, we design solutions for rather big entities in the financial services area, and we prefer to have our deployment mappings in XML, since it's easy to change without having to recompile. We would like to do our development using annotations and generate from them the orm.xml mapping files. I found this proof of concept annotation...

Internal HSQL database complains about privileges

I'm setting up a standalone Java service with an in-process, in-memory HSQL database. Persistence.xml <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" ...

Please explain about: insertable=false, updatable=false

Please rest assure that I did some search trying to understand about this as much as possible, but most of the community posts are about implementation instead of explanation. I guess I just dont understand it correctly, but if a field is annotated insertable=false, updatable=false, doesnt it mean that you cannot insert value nor change ...

How to inject PersistenceContext during unit testing?

This is my java class: public class Finder { @PersistenceContext(unitName = "abc") EntityManager em; public boolean exists(int i) { return (this.em.find(Employee.class, i) != null); } } This is the unit test: public class FinderTest { @Test public void testSimple() { Finder f = new Finder(); assert(f.exists(1) =...

How to specify SQL comments through JPA annotations?

Is there any way to specify SQL comments through JPA annotations? Comments for tables and columns. ...

Java Newbie: JPA and EJB workflow question

I'm just learning about JPA and session beans. I've worked through a simple database model (schema designed using MySQL Workbench) and used an IDE (NetBeans) wizard to generate the JPA entity classes and session beans. My question has to do with an appropriate workflow when the data model changes. For example, if I add a column to a tab...

how to raise OptimisticLockException

Unable to catch optimistic lock exception. one way to raise OptimisticLockException is by using em.flush() try{ //some enitity em.flush() } catch(OptimisticLockException ole){} but i dont think this is best solution beacuse in this full database is flush. another work around is by catching EJBException and find RollBackExce...

Optimistic Lock Exception with Foreign Keys

We are using JEE5 with GlassFishV2.1 and MySQL 5.1 and this is related to OptimisticLockException that we get. We have two database tables. First table is USER: having UserId and EmailId columns. Second table is SME_ACCOUNT with AdminId, SharedId, SpaceLeft and Version field which is managed by javax.persistence.Version (@version anno...

How and who should inject PersistenceContext when running tests through Jersey/Grizzly?

I have this class (mix of JAX-RS/Jersey and JPA/Hibernate): public class Factory { @PersistenceContext(unitName = "abc") EntityManager em; @Path("/{id}") @GET public String read(@PathParam("id") int i) { return em.find(Employee.class, i).getName(); } } This is the unit test: public class FactoryTest extends JerseyTest...

what dependencies my project should have if I'm using JPA in Hibernate?

I use JPA, and Hibernate as its implementation. What maven2 dependencies I need to have in my project? ...

How to get all the element from JDBC query

HI, I have query like this final Query contractQuery = cgnDao.getEntityManager(). createNativeQuery("SELECT k.phrase, ak.type FROM key k INNER JOIN adkey ak USING (key_id) WHERE pck.pub_id =" + pid +" AND pck.c_id =" + campId ); How can i get each and every element from the query? Where phrase is an String and type is...

Hibernate JoinColumn default name mssing '_id'

@ManyToOne(fetch = FetchType.LAZY) @JoinColumn (name = "account_id") private Account account; Works fine. @ManyToOne(fetch = FetchType.LAZY) @JoinColumn private Account account; Exception : Missing column account in SomeSchema.SomeOwnerTable * JPA Spec says default join column name is property name ( 'account') + '_' + target tabl...

OptimisticLockException with 2 foreign keys

Hello, This is in continuation with the question I logged as a "Unregistered User". I did not find a way to add comments (as suggested by Plínio Pantaleão) to that question, so created a "Registered Account" and this question. Apologies if there really was a wy to do this. Please refer to http://stackoverflow.com/questions/3812968/opti...

Strategies for performance optimizations on an inherited EJB3 application

I was asked to have a look at a legacy EJB3 application with significant performance problems. The original author is not available anymore so all I've got is the source code and some user comments regarding the unacceptable performance. My personal EJB3 skill are pretty basic, I can read and understand the annotated code but that's all ...

why my JPA annotated classes are not discovered implicitly?

My persistence.xml looks like: <persistence> <persistence-unit name="test"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>com.XXX.Abc</class> <properties> <property name="hibernate.archive.autodetection" value="true" /> .. </properties> </persistence-unit> <persistence> Everything w...

jpa update for objects having comosite primary key

I have a composite primary key for my object.How can i use a jpa to update my object? Normally we use the following code EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa"); EntityManager em = emf.createEntityManager(); Student stud1 = em.find(Student.class,1); stud1.setSname("Deepak"); //set others em.merge(stud1)...

Using Spring defined transactionManager in JPA/Hibernate

Suppose you use JPA with Spring, with Hibernate as JPA implementation. JPA transaction mode is "JTA", so you need to pass the container transactionManager to Hibernate. The classical answer is to set hibernate.transaction.manager_lookup_class to the matching class for your server. However, I think it's a shame to have this depend of ser...

how to catch OptimisticLockException in web layer

I'm having one issue that is how to catch OptimisticLockException in web layer (.war code) when it is raised by the EJB layer. We are using JEE5, GlassFishV2.1 and JPA (with TopLinks)and Container Managed Transactions.But when the dirty read occur due to trnasaction by another concurrent user on the same entity.It gives Transaction.Roll...

JPA entity without id

I have database with next structure: CREATE TABLE entity ( id SERIAL, name VARCHAR(255), PRIMARY KEY (id) ); CREATE TABLE entity_property ( entity_id SERIAL, name VARCHAR(255), value TEXT ); When I try to create EntityProperty class @Entity @Table(name="entity_property") public class EntityProperty { pri...