org.hibernate.MappingException: Unknown entity: annotations.Users

The Hibernate configuration file must define the entity classes: <mapping class=”annotations.Users”/> Or you must explicitly add the class to the configuration using configuration.addClass(annotations.Users.class) // Read mappings as a application resourceName // addResource is for add hbml.xml files in case of declarative approach configuration.addResource(“myFile.hbm.xml”); // not hibernateAnnotations.cfg.xml

Configure JPA to let PostgreSQL generate the primary key value

Given the table definition: CREATE TABLE webuser( idwebuser SERIAL PRIMARY KEY, … ) Use the mapping: @Entity @Table(name=”webuser”) class Webuser { @Id @SequenceGenerator(name=”webuser_idwebuser_seq”, sequenceName=”webuser_idwebuser_seq”, allocationSize=1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator=”webuser_idwebuser_seq”) @Column(name = “idwebuser”, updatable=false) private Integer id; // …. } The naming tablename_columname_seq is the PostgreSQL default sequence naming for SERIAL and I recommend that you … Read more

Java entity – why do I need an empty constructor?

An empty constructor is needed to create a new instance via reflection by your persistence framework. If you don’t provide any additional constructors with arguments for the class, you don’t need to provide an empty constructor because you get one per default. You can also use the @PersistenceConstructor annotation which looks like following @PersistenceConstructor public … Read more

Entity Framework and Multi threading

First off, I’m assuming you have read the article “Multithreading and the Entity Framework” on MSDN. Solution #1 is almost certainly the safest from a threading perspective, since you are guaranteeing that only one thread is interacting with the context at any give time. There is nothing inherently wrong with keeping the context around- it … Read more

JPA, How to use the same class (entity) to map different tables?

Not sure you can do it exactly as you want but you can use inheritance to produce the same result. AbsT has all the fields but no @Table annotation Ta and Tb inherit from AbsT and have an @Table annotation each Use @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) in AbsT. Sample code: @Entity @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) public class abstract AbsT { @Id … Read more

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