3

I think in Hibernate 3 there was a property key hibernate.packagesToScan
which one could set at the session factory level in hibernate.cfg.xml.
Is this key changed in Hibernate 4 and if so, what is its corresponding key?

I am using version 4.3.8 final.

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
peter.petrov
  • 38,363
  • 16
  • 94
  • 159

1 Answers1

1

In hibernate properties you need:

<property name="hibernate.archive.autodetection" value="class, hbm" />

In persistence.xml you need:

<exclude-unlisted-classes>false</exclude-unlisted-classes>
Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
  • Can I just go without using persistence.xml and JPA respectively? See also these 2 related questions, you'll get a better idea what I'm trying to achieve: http://stackoverflow.com/questions/28107513/hiberate-4-3-entity-class-instances-not-returned-in-list http://stackoverflow.com/questions/28097847/hibernate-4-3-x-load-all-entity-annotated-classes – peter.petrov Jan 23 '15 at 10:35
  • Try with the hibernate property first. It should be ok even if you don't have persistence.xml – Vlad Mihalcea Jan 23 '15 at 10:40
  • You mean I put that in hibernate.cfg.xml ? I am fine even with calling `addPackage` programmatically, my main problem is that Hibernate doesn't really recognize my persistent classes even in that case, I cannot create a simple `Criteria` and do `list` on it (I get empty list back?!). +1 for trying to help. – peter.petrov Jan 23 '15 at 10:43
  • Btw, based on some research I did, I think it turned out `hibernate.packagesToScan` is a Spring-specific thing. I am not using Spring in this project, so it does not help. – peter.petrov Jan 23 '15 at 11:00
  • It should go in hibernate.cfg.xml. If you get an empty list, it's because you have no data. If you supply a Class that not a Hibernate entity, you get an exception, not an empty list. – Vlad Mihalcea Jan 23 '15 at 11:01
  • I have data because if I do `session.createSQLQuery` and not `session.createCriteria`, and I query the same table (using the 1st approach), it works fine and it returns about 100 records. – peter.petrov Jan 23 '15 at 11:02
  • Make sure the entity table matches the one you used in the SQL query. – Vlad Mihalcea Jan 23 '15 at 11:07
  • Well, I did, it's called `Category`, the underlying RDBMS is MySQL. Thanks anyway, I'll keep looking for a solution, I'm sure it's something simple I'm missing here. – peter.petrov Jan 23 '15 at 11:10
  • Also, I have SQL logging enabled, note that when I use `Criteria`, hibernate doesn't generate any SQL at all to the RDBMS. I have no idea why. And when I use `createSQLQuery` I can see "select * from..." generated. – peter.petrov Jan 23 '15 at 11:23
  • That's weird indeed. Usually you get an Exception, when the entity is not resolved. I haven't heard of not having the SQL generated at all. – Vlad Mihalcea Jan 23 '15 at 11:53