Hibernate problem – “Use of @OneToMany or @ManyToMany targeting an unmapped class”

Your annotations look fine. Here are the things to check: make sure the annotation is javax.persistence.Entity, and not org.hibernate.annotations.Entity. The former makes the entity detectable. The latter is just an addition. if you are manually listing your entities (in persistence.xml, in hibernate.cfg.xml, or when configuring your session factory), then make sure you have also listed … Read more

How to import initial data to database with Hibernate?

I found this by doing a search on “Hibernate fixtures” : Hibernate will create the database when the entity manager factory is created (actually when Hibernate’s SessionFactory is created by the entity manager factory). If a file named import.sql exists in the root of the class path (‘/import.sql’) Hibernate will execute the SQL statements read … Read more

JPA 2.0 : Exception to use javax.validation.* package in JPA 2.0

As @Korgen mentioned in comments hibernate-validator-5.x.x isn’t compatible with validation-api-1.0.x. This is because of moving to new specification JSR-303 -> JSR-349. There are two ways to solve this issue: 1. Downgrade hibernate validator version (which is implements JSR-303): <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.3.1.Final</version> </dependency> 2. If you don’t want to move back from hibernate validator 5 … Read more

Why do I need to configure the SQL dialect of a data source?

Dialect means “the variant of a language”. Hibernate, as we know, is database agnostic. It can work with different databases. However, databases have proprietary extensions/native SQL variations, and set/sub-set of SQL standard implementations. Therefore at some point hibernate has to use database specific SQL. Hibernate uses “dialect” configuration to know which database you are using … Read more

Hibernate Search: How to use wildcards correctly?

Updated answer for Hibernate Search 6 Short answer: don’t use wildcard queries, use a custom analyzer with an EdgeNGramFilterFactory. Also, don’t try to analyze the query yourself (that’s what you did by splitting the query into terms): Lucene will do it much better (with a WhitespaceTokenizerFactory, an ASCIIFoldingFilterFactory and a LowercaseFilterFactory in particular). Long answer: … Read more