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
My understanding is that most application servers will automatically look for classes annotated with @Entity when a META-INF/persistence.xml file is encountered and the transaction-type is JTA.
I believe if the transaction type is RESOURCE_LOCAL, you need to specify which classes to scan.
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.