Note that I must to declare my entity User (and others ones). I'd like just indicate the entities package like a scan.
How can I do?
If you mean that you want your entities to be scanned in from some Java class rather than mentioning each entity in the persistence.xml file, then I suggest you take a look at org.hibernate.cfg.Configuration#addAnnotatedClass(Class annotatedClass). You will have a HibernateUtil class where you initiate the sessionFactory object, so make changes something like this
Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
The JPA spec explains which classes are scanned for annotations. Section 22.214.171.124 to be precise in JPA 2 spec. To summarize:
The set of managed persistence classes that are managed by a persistence unit is defined by using one or more of the following:
- Annotated managed persistence classes contained in the root of the persistence unit (unless the exclude-unlisted-classes element is specified)
- One or more object/relational mapping XML files
- One or more jar files that will be searched for classes
- An explicit list of classes
Take a look at the xsd of persistence.xml, especially the jar-file element where you can specify additional jars (that are in the classpath) for annotation scanning.