jpa

Difference Hibernate 3.5 / JPA 2.0

So far, I always prefered to use Hibernate directly rather than JPA 1.0, because JPA was lacking some of the important features I needed and Hibernate provided: Criteria API, second level cache, unidirectional OneToMany and a few others. Now, with the advent of JPA 2.0 and all the new features that come with it and that were initially m...

Hibernate JPA - ManyToOne relationship not populated

I'm currently moving a (working) app from using EclipseLink to Hibernate JPA, mostly it's gone quite smoothly, but I'm finding one thing that I can't explain, and also can't think of any good search terms! Basically, I have four entities, with one-to-many relationships forming a chain: EntityA has a list of EntityB's, each of which has...

List Hibernate configuration parametrs

Is there a way to programatically get Hibernate configuration parameter values, if I have access to a SessionFactory object? I would like to list the configuration in a GUI view, for debuging purposes. ...

Quering JPA TABLE_PER_CLASS mapping on One to One relationship

I am trying to map a JPA (using Hibernate) one-to-one relationship with a inheritance strategy TABLE_PER_CLASS. Here is an example: @Entity public class DrivingLicense { @OneToOne(targetEntity = Human.class, cascade = CascadeType.ALL, fetch=FetchType.LAZY) @JoinColumn private Human human; @SuppressWarnings("unchecked")...

JPA/Hibernate Native Queries do not recognize Parameters

I am using Hibernate/JPA to execute native PostGIS queries. The problem with these queries is that they need parameters that are not of the classical X = 'value' form. For example, the following lines crash String queryString = "select * from Cell c where ST_DWithin(c.shape, SetSRID(ST_GeomFromEWKT('POINT(:lon :lat)'),4326), 0.1)"; ...

How to implement equals() and hashcode() methods in BaseEntity of JPA?

I have BaseEntity class which is a superclass of all JPA entities in my application. @MappedSuperclass public abstract class BaseEntity implements Serializable { private static final long serialVersionUID = -3307436748176180347L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID", nullable=false...

Is it illegitimate to name an JPA entity "Group"?

I'm developing a JEE6-application, using JPA 2.0 and Hibernate 3.5.2-Final as the Provider (and MySQL 5.1.41). My Application Server is Glassfish V3.0.1. I already have a working CRUD-app with some entities and relationships. Now i added an (really simple) entity with the name "Group". The entity class looks like this: package model //...

Removing parent and all children

Hi, I have a problem removing the parent entity from the database. The code looks like this: public class Parent implements Serializable { @Id @GeneratedValue(strategy = GenerationType.TABLE) private Long id; @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN) @OneToMany(cascade = CascadeType.ALL, fetch = FetchTy...

Persisting set of Enums in a many-to-many unidirectional mapping

I'm using Hibernate 3.5.2-FINAL with annotations to specify my persistence mappings. I'm struggling with modelling a relationship between an Application and a set of Platforms. Each application is available for a set of platforms. From all the reading and searching I've done, I think I need to have the platform enum class be persisted a...

Getting 'Named query not found' with Spring framework

I have a Java class (Entity) with a set of named queries. When the Spring tries to inject the related bean, it is not finding one of the queries. As example: @NamedQueries({ @NamedQuery(name = "Query1", query = "..."), @NamedQuery(name = "Query2", query = "..."), @NamedQuery(name = "Query3", query = "..."), ...

Java/Hibernate JPA: InheritanceType.TABLE_PER_CLASS and IDs

I'm using Hibernate JPA. Suppose I have these classes: AbstractPerson |--> ConcreteEmployee |--> ConcreteCustomer Is there any way to make the concrete classes have independent IDs? I'm using InheritanceType.TABLE_PER_CLASS. ...

How to programmatically get transaction manager in a thread ?

I have a wicket page , which contains two Spring-managed beans , one is DAO , another is Service Object : public class MergeAccountsPage extends WebPage { @SpringBean private MergeEmailDao mergeEmailDao; @SpringBean private MergingService mergingService; } The MergingService's implementation's methods are mostly annotated wit...

Good way to handle large collection in a domain model - with JPA/Hibernate ORM?

I have some OneToMany child collections in my domain classes that may grow over time to hold hundreds or (very likely) thousands of instances. However, often times the only thing the parent really needs is the "first" child or the "last" child or the "biggest" child. Having the parent instance loop through a large collection of objects...

How to generate case sensitive columns with JPA in MySQL automatically

How can I order JPA to set a MySQL database column with text content as case sensitive by default upon creation? ...

GlassFish 2.1.1 - TopLink (JPA1) Persistence Exception 7106 - String Encryption Mistery...

I'm using NetBeans 6.8 and Glassfish Enterprise Server 2.1.1 ((v2.1 Patch06)(9.1_02 Patch12)) (build b31g-fcs). I created a servlet and used Netbeans code generation features to imlement persistence using TopLink (JPA1). When I try to create an Entity Manager with the following code: EntityManagerFactory entityManagerFactory=Persiste...

Large Objects may not be used in auto-commit mode

Hello, I have a Spring application which uses Hibernate on a PostgreSQL database. I'm trying to store files in a table of the database. It seems it stores the row with the file (I just use persist method on EntityManager), but when the object is loaded from the database I get the following exception: org.postgresql.util.PSQLException: ...

JPA Compound key with @EmbeddedId

In a legacy database, I have three tables: Users, Workgroups, and UsersWorkgroup. UsersWorkgroup stores what role a user has in a workgroup. Here are the relevant code snippets: @Entity @Table(name = "users_workgroup") public class UsersWorkgroup implements Serializable { private static final long serialVersionUID = 1L; @Embedde...

how inject a EntityManager between ear

I'm using JBoss 4.2.3 and I deployed two ears called triad-1.0.ear and reportservices-1.0.ear, the thing is that I want to use the entity manager of the project triad in the project reportservices. This is the architecture JBoss follows: triad-1.0.ear: triad-core-1.0.jar: META-INF: ...

Can I name my constraints with JPA?

When I use the maven-hibernate3-plugin (aka hbm2ddl) to generate my database schema, it creates many database constraints with terrifically hard-to-remember constraint names like FK7770538AEE7BC70 . Is there any way to provide a more useful name such as FOO_FK_BAR_ID ? If so, it would make it a tad easier to track down issues in the lo...

direct access to ehcache and only use hibernate on a cache miss

Env: Seam 2.2.0, JPA, Hibernate 3.3.x, ehcache-core 2.0.1 Here are some observations on using a cache along with Hibernate. We are already using the 2nd level cache but not quite comfortable with the response times. The third option mentioned in the above reference (Direct access to EHCache, only use Hibernate on a cache miss: 20 secon...