How to specify packagesToScan in HibernateJpaAutoConfiguration?

From the Spring Boot reference… 62.4 Separate @Entity definitions from Spring configuration Spring Boot tries to guess the location of your @Entity definitions, based on the @EnableAutoConfiguration it finds. To get more control, you can use the @EntityScan annotation, e.g. @Configuration @EnableAutoConfiguration @EntityScan(basePackageClasses=City.class) public class Application { //… }

Problems mapping UUID in JPA/hibernate

Extending Mike Lively’s answer with a code sample & referring to Oracle too. I had this problem with the OracleDialect (Oracle10gDialect). Adding an annotation @Type to the UUID field fixed it for me. @Id @Type(type=”uuid-char”) private UUID id; Note: also used a TwoWayStringBridge on this field, using the @FieldBridge annotation. Note: type=”uuid-binary” did not work; … Read more

Unable to resolve name [org.hibernate.dialect.MySQL5Dialect ] as strategy [org.hibernate.dialect.Dialect]

Since you errormessage contains that suspicious extra space at the end: Unable to resolve name [org.hibernate.dialect.MySQL5Dialect ] I will take a wild guess that you have an extra space at the end of your dialect property. So look for “org.hibernate.dialect.MySQL5Dialect ” and change it to: “org.hibernate.dialect.MySQL5Dialect”

Class “model.Address” is listed in the persistence.xml file but not mapped

This is an Eclipse quirk. I recently had exactly this problem when I created a new JPA project with the JPA library configuration disabled, but didn’t manually configure the JPA libraries before I created the entities by the Eclipse New JPA Entity wizard. After creating the entities I configured the JPA libraries in project’s Build … Read more

How to mock EntityManager? [closed]

I suggest to use Mockito Framework it is very easy to use and understand. @Mock private EntityManager entityManager; If you want to use any method that belongs to entityManager, you should call. Mockito.when(METHOD_EXPECTED_TO_BE_CALLED).thenReturn(AnyObjectoftheReturnType); When you run your test, any call previosly declared in the Mockito.when for the EntityManager will return the value put in the … Read more

@Id @GeneratedValue but set own ID value

It may be an overkill but have you thought about writing your own CustomIDGenerator which probably subclasses say the AutoGenerator of hibernate and exposes a couple of methods where you can set the id of the next class object to be generated so for example class MyGenerator extends …. { public void setIdForObject(Class clazz, Long … Read more

JPA Implementations – Which one is the best to use? [closed]

I had the same conclusions about these implementations. OpenJPA was/seemed buggy Hibernate had tons of libraries and seemed to have trouble with not lazy loading everything. Toplink ended up as my choice. It was not as flexible as Hibernate would have been but it works and I don’t have to install commons-logging. The one I … Read more

Is it a good idea to “migrate business logic code into our domain model”?

As said We have a distinct layer for business logic (usually called Service layer) Domain-Driven-Design (DDD) states you should put business logic inside your domain model. And, believe me, it is really good. As said by POJO in Action book about Service layer It is Use Case driven It can define Transaction boundaries Before @Service … Read more

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