jpa

Create a custom JPA temporal annotation

I want some of mycoulmns in the JPA entity to take values from database during inserts/updates, i.e from Oracle sys_context, I believe JPA temporal annotation includes database generated timestamps during insert/updates, Is there any way I could create a custom annotation somewhat simailar to this or provide some default values during in...

JPA and toplink create-table on if they don't already exist?

Looks like jpa is something which makes me ask a lot of questions. Having added this <property name="toplink.ddl-generation" value="create-tables"/> my JPA application always creates tables when running, which results in exceptions in case the tables already exist. I would like JPA to check if the tables already exist and if not crea...

How to generate id based on two foreign keys in JPA / Hibernate?

I have a simple question regarding Entity declaration in JPA. I have an entity with 2 foreign keys, which are not null and form an uniqueConstraint. First I was thinking about a composite key, composed of the two foreign keys, but I heard that this is a legacy design, and not the recommended way of designing new tables. So I am interest...

Is it possible to dynamically trigger calling of the @PostLoad method only on demand

Env: JBoss Seam, JPA, Hibernate We use the @PostLoad annotation to dynamically initialize some of the transient variables in our @Entity (sometimes this involves looking up the parent entity to initialize status - which is a costly operation). But under certain circumstances, we don't want this @PostLoad to get triggered, since we will...

Can I use the current release of Unitils (3.1) with JPA 2.0?

Using Hibernate EntityManager 3.5.3-Final together with Unitils 3.1 results in: unitilsAfterTestTearDown(com.unifiedpost.payments.model.TestAccount) Time elapsed: 0.02 sec <<< FAILURE! java.lang.AbstractMethodError: org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMo...

Generated primary keys start form 9951 instead of the 10000

Hello, I make use of: NetBeans IDE 6.7.1, GlassFish v2.1, Oracle 10g XE, JAVA 6 SE, JAVA 5 EE, From inside a stateless EJB I persist entities of type customer I have the annotation: @SequenceGenerator(name="seq", sequenceName="cust_id_seq") in the class customer so the primary keys are autogenerated in the database from the seque...

JPA and GregorianCalendar

Does JPA 1.0 support mapping of GregorianCalendar? I didn't find anything in JPA 1.0's mapping file specification about GregorianCalendar. What about JPA 2.0? ...

Implementing lazy loading of a many-to-many on EJB3 beans

I have two database tables, User and Role. I'm trying to set up a bidirectional many-to-many mapping in my application but I'm running into performance issues when eagerly fetching. The many-to-many works using a UserRole join table. My DTOs look like this (fat has been trimmed): UserDTO.java @Entity @Table(name = "[redacted].User") pu...

How to choose DDL Primary Key constraint names with JPA/Hibernate

There exists a proprietary hibernate annotation to specify the Foreign Key constraint names that are used at DDL generation time: org.hibernate.annotations.ForeignKey. Is there also a way to specify the Primary Key constraint names? ...

JPA and database in a single jar

Hi all I created an app which uses JPA and MySQL. Now I like to create simple desktop application out of it (eg a simple jar would be best). Two questions: What's the easiest way to get a project including all jars it depends on out of eclipse in a simple jar? Can I use a database like sqlite or derby which requires no installation (e...

How to define JPA?

Hi, I have just joined a on going project based on spring framework. It usage hibernate as ORM system. and it is well integrated. I have learned a lot with this project. But some how i am not satisfied with my understanding of hibernate, JPA, when they are mixed together. It has been very confusing for me to understand when my PM is tal...

JPA OneToMany problems after update

I have 2 Classes, Parent and Child, with a @OneToMany relationship. Every parent has 0 or more children. @OneToMany(fetch=FetchType.LAZY, cascade={CascadeType.REMOVE}) The Parent class has also other fields like the name. I'm in a Container env, so my UI is made of JSP. When I want to change the Parent object I have to pass it to a...

JPA 2 Delete/Insert order from Metamodel

I'm trying to use the JPA2 metadata to figure out the order to insert/delete rows from a database so constraints are not an issue (to be used later in Java code). This is part of a backup/restore approach using JPA. Here's my approach: Group tables by amount of relationships/constraints (Only one-to-many and one-to-one are considered)...

Problem when persisting Entity

@Entity @Table(name = "jobitems") @IdClass(JobItemId.class) public class JobItem implements Serializable { @ManyToOne @PrimaryKeyJoinColumn(name = "forumId") private Forum forum; @ManyToOne @PrimaryKeyJoinColumn(name = "parsingJobId") private ParsingJob parsingJob; @Id @Column(name = "forumId", insertable = false, updatable = ...

How to create relationship to the same entity with JPA (Hibernate)?

I have an entity User and it should have property manager where manager is another user (one manager can manage many users, any user may have only 1 manager or have not any). How can I implement this? I tried something standard @ManyToOne @JoinColumn (name = ??? /* what should be here? */, nullable = true) private User manager; but ...

Filter list contained in entity returned by jpa/hibernate query

Hi all, I have a simple jpa entity 'ApplicationForm' with a one to many list in it: @OneToMany(cascade=CascadeType.REMOVE, mappedBy="textQuestion") private List<Dictionary> questions; The variable Dictionary contained in ApplicationForm is just another plain entity with just the text of the question. The corresponding database tab...

JPA Entity is not being persisted after exception

Hi guys! I´m having the following problem: I have 2 classes (A and B). The class A has a method (method1) annotated with @Transaction(noRollBackFor = ExceptionB.class) that calls the method2 from class B. ExceptionB is a non-checked RunTimeException. public class A { ... @Resource private B b; @Transaction(noRollBackF...

JPA - Using insertable/updatable

I am writing a webservice to maintain a database. I am trying to use JPA (EclipseLink) for the entity classes. However, the database uses natural primary keys and therefore there's potential that an update on the ID fields will fail due to foreign key constraints. Our DBA has provided a function to update the ID fields which will crea...

Logging JDBC/Hibernate/JPA transaction isolation levels

I'm working on a Flex/BlazeDS/Spring/JPA/Hibernate web application hooked up to a Microsoft SQL Server database. It seems to be locking the tables too aggresively. From my research, it looks like using the snapshot isolation policy is the best bet. I've set things up as such: <bean id="entityManagerFactory" class="org.springf...

The difference between annotating fields and methods in JPA (Hibernate)?

Are there any statements in JPA spec or official docs about certain JPA implementations which describe the behavior when we annotate entity's methods and when we annotate entity's fields? Just a few hours ago I met an ugly problem: I use JPA (via Hibernate, but without anything Hybernate-specific in java code) with MS SQL Server. And I ...