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

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

what is difference between a Model and an Entity

The definition of these terms is quite ambiguous. You will find different definitions at different places. Entity: An entity represents a single instance of your domain object saved into the database as a record. It has some attributes that we represent as columns in our tables. Model: A model typically represents a real world object … Read more

Entity Framework 4.1 InverseProperty Attribute and ForeignKey

It is theoretically correct but SQL server (not Entity framework) doesn’t like it because your model allows single employee to be a member of both First and Second team. If the Team is deleted this will cause multiple delete paths to the same Employee entity. This cannot be used together with cascade deletes which are … Read more

Instantiating a context in LINQ to Entities

Creating a new ObjectContext each time does involve ‘some’ overhead. Essentially the overhead involved is copying metadata from a global cache into metadata associated with the specific ObjectContext. This overhead is relatively minor, so often it is not worth worrying about, especially when you consider the extra safety inherent in the using pattern. For me … Read more

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

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