hibernate-mapping

hibernate and generic field mapping

本秂侑毒 提交于 2019-12-01 12:01:57
I want to map a generic field in a superclass with Hibernate. My mother class is : @Entity @Table(name = "ParameterValue") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "parameterType", discriminatorType = DiscriminatorType.STRING) public abstract class ParameterValue<C> { private C value; /* HELP NEEDED HERE */ public C getValue() { return value; } public void setValue(C value) { this.value = value; } } One subclass : @Entity @DiscriminatorValue(value = "integer") @AttributeOverride(name = "value", column = @Column(name = "intValue")) public class

mixing joined and single table inheritance and querying for all objects

六眼飞鱼酱① 提交于 2019-12-01 10:31:17
问题 I have a webapp that is working with the following configuration (I changed the entity names): @Entity @Inheritance(strategy = InheritanceType.JOINED) @Table(name = "animals") public abstract class Animal { ... @MappedSuperclass @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "type") public abstract class Mammal extends Animal { ... @Entity @Table(name = "mammals") @PrimaryKeyJoinColumn(name = "mammal_id") @DiscriminatorValue(value = "dog") public class Dog

How to store image into postgres database using hibernate

孤者浪人 提交于 2019-12-01 06:50:01
I want to store image into database using hibernate and Java. I am using postgres database I tried bytea data type to store image and byte[] data type in hibernate pojo. I used the following code, CREATE TABLE photo ( "photo_name" bytea ) WITH (OIDS=FALSE); ALTER TABLE photo OWNER TO postgres; Hibernate Pojo public class PhotoEntity { byte[] name; public byte[] getName() { return name; } public void setName(byte[] name) { this.name = name; } } but it gives error at time of mapping. please give me any reference to do this. Craig Ringer If you are using Hibernate via JPA2, you may need the @Lob

Hibernate Bidirectional ManyToMany delete issue

让人想犯罪 __ 提交于 2019-12-01 06:47:17
In my project I have entities for users and companies: @Entity @Table(name = "users") public class UserDetails { @Id @GeneratedValue @Column(name = "user_id") private int id; @Column(name = "first_name") @NotEmpty @Size(min = 2, max = 20) private String firstName; @ManyToMany(cascade = CascadeType.REFRESH) @JoinTable(name = "users_companies", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "company_id")) private Set<CompanyDetails> userCompanies = new HashSet(); //getters and setters of course... } @Entity @Table(name = "companies") public class

How to store image into postgres database using hibernate

六眼飞鱼酱① 提交于 2019-12-01 05:26:23
问题 I want to store image into database using hibernate and Java. I am using postgres database I tried bytea data type to store image and byte[] data type in hibernate pojo. I used the following code, CREATE TABLE photo ( "photo_name" bytea ) WITH (OIDS=FALSE); ALTER TABLE photo OWNER TO postgres; Hibernate Pojo public class PhotoEntity { byte[] name; public byte[] getName() { return name; } public void setName(byte[] name) { this.name = name; } } but it gives error at time of mapping. please

Native SQL throwing Invalid Column Name Exception

浪尽此生 提交于 2019-12-01 03:42:57
I am using Hibernate 3.2.5 for my application. I have a Dept table and an Employees table. Dept.java private int deptId; private String deptName; private Map empMap = new HashMap(); //Getters and Setters Employees.java private int empId; private String empName; private int deptId; private int age; private String sex; private Dept dept; HBM Mapping file <class name="com.jdbc.Dept" table="dept"> <id name="deptId" type="integer" column="DEPT_ID"> <generator class="assigned"></generator> </id> <property name="deptName"> <column name="DEPT_NAME"></column> </property> <map name="empMap" inverse=

Hibernate is not auto-creating a table that does not exist in the DB

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 02:14:44
I have a basic Hibernate code, I have set the property "hibernate.hbm2ddl.auto" as update still it is not auto-creating the table in the Database. These are the required files: employee.hbm.xml <hibernate-mapping> <class name="contacts.employee" table="contacts"> <meta attribute="class-description"></meta> <id column="contactId" name="contactId" type="string"> <generator class="assigned"/> </id> <property column="contactName" length="100" name="contactName" not-null="true" type="string"/> <property column="password" length="100" name="password" not-null="true" type="string"/> <set cascade="all

Native SQL throwing Invalid Column Name Exception

…衆ロ難τιáo~ 提交于 2019-12-01 01:46:13
问题 I am using Hibernate 3.2.5 for my application. I have a Dept table and an Employees table. Dept.java private int deptId; private String deptName; private Map empMap = new HashMap(); //Getters and Setters Employees.java private int empId; private String empName; private int deptId; private int age; private String sex; private Dept dept; HBM Mapping file <class name="com.jdbc.Dept" table="dept"> <id name="deptId" type="integer" column="DEPT_ID"> <generator class="assigned"></generator> </id>

Hibernate is not auto-creating a table that does not exist in the DB

爷,独闯天下 提交于 2019-11-30 21:42:34
问题 I have a basic Hibernate code, I have set the property "hibernate.hbm2ddl.auto" as update still it is not auto-creating the table in the Database. These are the required files: employee.hbm.xml <hibernate-mapping> <class name="contacts.employee" table="contacts"> <meta attribute="class-description"></meta> <id column="contactId" name="contactId" type="string"> <generator class="assigned"/> </id> <property column="contactName" length="100" name="contactName" not-null="true" type="string"/>

Cannot delete or update a parent row: a foreign key constraint fails (hibernate xml mapping)

那年仲夏 提交于 2019-11-30 20:41:40
问题 I would like to delete all the groups among which a user is an owner but it does not work at the moment. I think that there is something which is lacking at the level of the mapping User.hbm.xml or Group.hbm.xml but I do not know. Error is "Cannot delete or update a parent row: a foreign key constraint fails ( sharedmap . groupe , CONSTRAINT FK_gq7win10rtxufsxu1n5istm2p FOREIGN KEY ( user_id ) REFERENCES user ( id ))" Here are the classes and the files xml concerned: User.java public class