hibernate-mapping

foreign key must have same number of columns as the reference primary key hibernate - many to many

安稳与你 提交于 2019-12-11 04:04:13
问题 I have domain Classes - User, Role, Group, Group Role User Domain private long id, private String userName, private String password, Set<Role> roles = new HashSet<Role>(); User.hbm.xml <hibernate-mapping package="uk.co.jmr.sdp.domain"> <class name="User" table="user"> <id name="id" unsaved-value="-1"> <generator class="native"/> </id> <property name="userName" column="user_name"/> <property name="password" column="password"/> <property name="emailId" column="email_id"/> <set name="roles"

Many to many hibernate mapping with extra columns?

穿精又带淫゛_ 提交于 2019-12-11 03:37:00
问题 Hi i have many to many mapping with extra columns in the join table. table structure look like this. table vendor{vendor_id, vendor_name, vendor_password, etc...} table student{student_id, student_name, student_password, etc..} table test{test_id, test_subject, test_price,test_level, etc..} Relations as follows vendor to test --> many-to-many student to test --> many-to-many link table vendor_student_test{vendor_id, student_id, test_id, purchasedDate, assignedDate, writtenDate, result} i

Hibernate throws TransientPropertyValueException when saving an entity

拥有回忆 提交于 2019-12-11 00:27:37
问题 I have two related entities, Institution and Registration, such that there is a many-to-one relationship between Registration and Institution. Thus we should be able to have registration entries for a single institution. The entities and relationship mapping: @Entity public class Registration{ @NotNull @ManyToOne(optional=false) @JoinColumn(updatable=false, insertable=false) private Institution institution; } @Entity public class Institution{ @OneToMany(cascade={CascadeType.REMOVE,

is it possible to maintain the different schema in same entity class

前提是你 提交于 2019-12-10 16:27:56
问题 I have two schema(claim and policy). For both schema am using same Entity class. My problem is, claim schema has column city but policy schema does have city column. So If I use entity class by policy schema I get error. is this only the way to change the Entity class for each schema ? or is it possible to maintain the different schema in same entity class? My Entity class : @Entity @Table(name = "Table_name") public class X { @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name =

MappingException: Named query not known

空扰寡人 提交于 2019-12-10 13:12:33
问题 Trying to learn Hibernate, i am trying to learn how to execute NamedQuries but evertime i am getting Exception in thread "main" org.hibernate.MappingException: Named query not known .Please help me out here Error ( only the message, not showing complete stack ) Exception in thread "main" org.hibernate.MappingException: Named query not known: hibernate_tut_emp.Employee.FindCountOfNames at org.hibernate.internal.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:177) at org.hibernate

Mapping two domain classes in Grails

随声附和 提交于 2019-12-10 11:49:20
问题 I have two tables in our database that need mapped. The first is a Student table. It looks something like this: id first_name last_name major_code_1 major_code_2 And the Major table is like this: id description I need to map the major codes of the student, where major_code_1 and major_code_2 point to an id in the Major table. How could I do this? Thanks! 回答1: Here is a simple model which maps to your schema: class Student { String firstName String lastName Major firstMajor Major secondMajor

Place Hibernate configuration in a different location

馋奶兔 提交于 2019-12-10 11:08:07
问题 The ideal place for Hibernate configuration files (.hbm.xml) is .../tomcat/webapps/projectName/WEB-INF/classes/hbm But I want to place those configurations settings in a different location, say /usr/local/properties/hibernate How can I do that? If I place that configuration files in that location and if I start Tomcat then it gives me an error on loading that configurations saying hibernate.cfg.xml not found 回答1: To configure location of .cfg.xml file use Configuration.configure(File) instead

Hibernate @OneToMany throws MySQLSyntaxErrorException: You have an error in your SQL syntax

[亡魂溺海] 提交于 2019-12-10 11:01:12
问题 I try to retrieve a list with some fields from Contact and also a list of phones. For this, I'm using a query to Contacts; Also I've created a DTO with only that fields that I need. The query is: final StringBuilder query = new StringBuilder(); query.append("SELECT new com.tim.core.dto.client.MinimalContactDTO(c.id, c.version, c.name, c.title, c.email, c.createdDate, c.phones) " + " from CONTACT c "); query.append("where "); query.append("( c.localRecordStatus IS NULL "); query.append("OR c

from hibernate to mysql, default value mapping issue

狂风中的少年 提交于 2019-12-10 10:26:24
问题 hibernate xml mapping file does not support default value. So when i try to create a column with default value in mysql, then i run the hibernate save() method without setting the column value. the default value cannot be generated. i have done some search. according to this post: https://forums.hibernate.org/viewtopic.php?t=171&highlight=default+value&sid=84a014fd93dd9b680afc606f616ca4f6 it said hibernate does not support default value. we can use trigger instead. Any way we can do this

How to exclude an entity field when doing an update with JPA

筅森魡賤 提交于 2019-12-10 04:33:46
问题 Is there a way to make a field non-persistent at update operation but persistent at create operation with JPA - Hibernate 4? I tried it in this way @Transient @Id @Column(name = "USER_NAME", nullable = false, length = 75) private String userName; but with @Transient annotation the field will be transient across all CRUD operations and I want a way to specify that only on this operation is persistent (create). Is there a way to do this? Thanks! 回答1: As explained in this article, you need to