hibernate-mapping

how to create a composite primary key hibernate JPA?

旧时模样 提交于 2019-11-29 12:28:05
i try to create composite primary key in table from 2 foreign key using hibernate JPA,but gives me error.I find some solution on net but nothing The relations between tables looks like this: Table Client clientID(PK) FirstName LastName . Table CarService serviceID(PK) DescriptionOfFailure . . Table ServiceDepartment clientID(PK) serviceID(PK) price . implementation of my code looks like this: @Entity public class ServiceDepartmentBean implements ServiceDepartmentI { @EmbeddedId private ServiceDepartmentPK serviceDepartmentPK = new ServiceDepartmentPK(); @Column(name="clientID", nullable=false,

Can a @ManyToOne JPA relation be null?

放肆的年华 提交于 2019-11-29 12:27:19
问题 I have a table that has foreign key of another table (many to one relationship) but i want it to be nullable. Something like this: public class SubType() { @Id @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; } public class TopUp { @Column(nullable = true) @ManyToOne(optional = false, fetch = FetchType.LAZY) private SubType subType; } But @Column(nullable = true) throws the NullPointerException and says subtype can not be

How to use a child association property as a Map key in JPA parent entity

拈花ヽ惹草 提交于 2019-11-29 12:08:37
I'm having two entities Car and CarDescription where CarDescription is depending on another foreign key from the table Language . What I' trying to accomplish is to have a HashMap in Car such that whenever I'm having a Car entity-object I am able to access all descriptions from the language id. Entity Car.java @Entity @Table(name = "Car") public class Car extends AbstractTimestampEntity implements Serializable { private static final long serialVersionUID = -5041816842632017838L; @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name = "ID", unique = true, nullable = false) private

Proper Hibernate id generator for postgres serial/bigserial column?

ⅰ亾dé卋堺 提交于 2019-11-29 11:21:13
问题 My PostgreSQL tables have id's of type bigserial , meaning they are generated at the time rows are inserted (and thus, the id column's value is not supplied in the INSERT statement). I'm having difficulty finding the proper value for the <generator class="..."> attribute in my XML mapping file. The code below is the closest I've found that seems to be the closest for Postgres, but it's still performing a SELECT nextval(...) on the sequence before inserting (and explicitly including the id

Hibernate mapping: OneToMany and OneToOne on child object property

天大地大妈咪最大 提交于 2019-11-29 10:50:33
Here is parent class Enterprise. It has employers and one of them is president of enterprise. @Entity class Enterprise { // fields @OneToMany public List<Employee> getEmployers() // implementation @OneToOne public Employee getPresident() // implementation } Here is child Employee class. It has only info about Enterprise where he works. But question is what association should I use? @Entity class Employee { // fields // what association should I use? public Enterprise getEnterprise() // implementation } Given that you've defined the Enterprise -> Employers association with @OneToMany , which

Hibernate - BigDecimal column mapping for Custom Dialect

微笑、不失礼 提交于 2019-11-29 09:57:28
I'm using Hibernate as our Object-Relational Mapping, with a custom dialect for an obscure database. The Entity I'm retrieving from this database has a column thus: @Column(name = "GROSS_WEIGHT", precision = 9, scale = 3) private BigDecimal grossWeight; The database has this column defined as numeric with a precision of 9 and a scale of 3. I can see the SQL that Hibernate generates to retrieve the data, and when I perform the same Query using the database query tool it returns '9.68' for the GROSS_WEIGHT column. However, in the Entity that is retrieved by Hibernate, the 'grossWeight' field

AnnotationException: A Foreign key refering has the wrong number of column. should be 2

放肆的年华 提交于 2019-11-29 06:20:49
问题 I am mapping my classes with the tables of my database, but when running a test, I get the following error: Caused by: org.hibernate.AnnotationException: A Foreign key refering com.modulos.pvs.acceso.datos.entity.Provincia from com.modulos.pvs.acceso.datos.entity.Ciudad has the wrong number of column. should be 2 at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:429) at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:115) at org.hibernate.cfg

Hibernate mapping exception - Could not determine type for:

喜你入骨 提交于 2019-11-29 06:15:27
Im trying to configure my entities but hibernate throws the following exception: org.hibernate.MappingException: Could not determine type for: com.sd.entity.SDUserProductAcess, at table: SDUser, for columns: [org.hibernate.mapping.Column(productAccess)] [PersistEngine] Failed to initialize persistence engine!java.lang.NullPointerException These are my Entities: @Entity @Inheritance(strategy = InheritanceType.JOINED) public class SDObject { @Id @GeneratedValue private long sdId; private String sdType; public long getSdId() { return sdId; } public void setSdId(long sdId) { this.sdId = sdId; }

Hibernate map enum to varchar

自闭症网瘾萝莉.ら 提交于 2019-11-29 05:33:29
Suppose I have this enum: public enum TestEnum { EXAMPLE, FURTHER_EXAMPLE, LAST_EXAMPLE } With this mapping in the .hbm : <property name="testEnum" column="TEST_COLUMN"> <type name="org.hibernate.type.EnumType"> <param name="enumClass">p.a.c.k.TestEnum</param> </type> </property> The enum is sent to the database as 0 , 1 , 2 . I'd like the values to be instead stored as EXAMPLE , FURTHER_EXAMPLE or LAST_EXAMPLE in a varchar column. How can I map enum to a varchar column? bvulaj Add this as a parameter of EnumType: <param name="type">12</param> This is because 12 is equivalent to java.sql.Types

How to do multiple column UniqueConstraint in hbm?

孤人 提交于 2019-11-29 02:57:14
Working on some legacy hibernate code. How do I do the following with hbm.xml(hibernate mapping file) instead of with annotations? @Table(name="users", uniqueConstraints = { @UniqueConstraint(columnNames={"username", "client"}), @UniqueConstraint(columnNames={"email", "client"}) }) public class User implements Serializable { private static final long serialVersionUID = 1L; @Id private int id; private String username; private String email; private Client client; } Use the properties tag: ... <properties name="uk1" unique="true"> <property name="username" .../> <many-to-one name="client" .../> <