JPA/Hibernate support for migration?

I usually let Hibernate generate the DDL during development and then create a manual SQL migration script when deploying to the test server (which I later use for UAT and live servers as well). The DDL generation in Hibernate does not offer support for data migration at all, if you only do as much as … Read more

Spring Data JPARepository: How to conditionally fetch children entites

The lazy fetch should be working properly if no methods of object resulted from the getContacts() is called. If you prefer more manual work, and really want to have control over this (maybe more contexts depending on the use case). I would suggest you to remove contacts from the account entity, and maps the account … Read more

JPA 2 Criteria Fetch Path Navigation

Agree with you about that method, and the fact that you would expect it to allow what you say. Another option would be Join<Team, Player> p = t.join(Team_.players); t.fetch(Team_.players); c.select(t).where(cb.equal(p.get(Player_.age), age)); i.e do a join(), add a fetch() for it, and then make use of the join. This is illogical and only adds to the … Read more

Saving order of a List in JPA

There are some hacky ways of doing this in JPA 1, but it’s easiest to switch to a JPA 2 provider. The @OrderColumn annotation support is what you’re looking for. Eclipselink have an ok tutorial on how to use it.

Simultaneous use of Hibernate and Spring data jpa?

You need a single way of configuration you are now configuring both Hibernate and JPA. You should be using JPA for configuration so remove the hibernate setup. You are using Hibernate4 so you can take advantage of the, not so well known, HibernateJpaSessionFactoryBean of Spring. If you need access to the SessionFactory (which I assume … Read more

How do I do a JPQL SubQuery?

You need to test it with IN and subquery since both do work in JPQL (according to syntax reference they do work together). You may also look at MEMBER OF expressions. But there is a better approach in my opinion. Such queries are called correlated sub-queries and one can always re-write them using EXISTS: SELECT … Read more

Using the JPA Criteria API, can you do a fetch join that results in only one join?

Instead of root.join(…) you can use root.fetch(…) which returns Fetch<> object. Fetch<> is descendant of Join<> but it can be used in similar manner. You just need to cast Fetch<> to Join<> it should work for EclipseLink and Hibernate … Join<MyEntity, RelatedEntity> join = (Join<MyEntity, RelatedEntity>)root.fetch(“relatedEntity”); …

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)