hibernate-mapping

Specify default value in Hibernate's XML configuration file

北城余情 提交于 2019-12-22 04:33:10
问题 I'm configuring Hibernate via the mapping configuration file. <class name="Person" table="person"> <id name="id" column="id" type="long"/> <property name="name" column="name" type="string"/> <property name="age" column="age" type="integer"/> </class> How do I set age to be nullable and default to null? 回答1: <property name="age" type="integer"> <column name="age" not-null="false" default="null" /> </property> 来源: https://stackoverflow.com/questions/10610211/specify-default-value-in-hibernates

Specify default value in Hibernate's XML configuration file

荒凉一梦 提交于 2019-12-22 04:33:06
问题 I'm configuring Hibernate via the mapping configuration file. <class name="Person" table="person"> <id name="id" column="id" type="long"/> <property name="name" column="name" type="string"/> <property name="age" column="age" type="integer"/> </class> How do I set age to be nullable and default to null? 回答1: <property name="age" type="integer"> <column name="age" not-null="false" default="null" /> </property> 来源: https://stackoverflow.com/questions/10610211/specify-default-value-in-hibernates

How to define Friendship relationship using Hibernate?

点点圈 提交于 2019-12-22 03:38:11
问题 I need to have "FriendRequest" and "ListOfFriends" functionalities.Similar to facebook, which shows number of received friend requests and number of approved friends. By "FriendRequest", I mean to have a list of friend requests that the user receives. By "ListOfFriends", I mean to have a list of friends of the user. To achieve that, I defined following class but when I try to retrieve a user using its username, a "Stackoverflow" exception message will be thrown. It seems it goes into an

Hibernate: Why is binding for a field similar weather explicit @JoinColum annotation is used or not?

北慕城南 提交于 2019-12-21 22:04:07
问题 Is @JoinColum implicitly specified when we use any association type annotation like @OneToOne , @OneToMany , etc. Here is snippet from Student entity in association with Laptop entity Case 1) Without using explicit @JoinColum @OneToMany(cascade=CascadeType.ALL) private List<Laptop> laptops=new ArrayList<Laptop>(); Case 2) Using explicit @JoinColum @OneToMany(cascade=CascadeType.ALL) @JoinColumn private List<Laptop> laptops=new ArrayList<Laptop>(); When I check DEBUG both cases have "almost"

Hibernate does not delete orphans on OneToMany

社会主义新天地 提交于 2019-12-21 15:46:30
问题 I have the following pretty simple one to many relations: Team has a Set of players: @Entity(name = "TEAM") @Access(AccessType.PROPERTY) public class Team{ private Integer id; private String name; private Set<Player> players ; @Id @Column(name = "id") public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } @Column(name = "team_name") public String getName() { return name; } public void setName(String name) { this.name = name; } @OneToMany(cascade = {CascadeType

index not updating after external entity changes

馋奶兔 提交于 2019-12-21 05:28:14
问题 I'm currently working on a project to persist data with JPA 2.1 and to search entities using hibernate search 4.5.0.final. After mapping classes and indexing, the searching works fine. However, when I changed the value description of classB from "someStr" to "anotherStr". The database was updated accordingly, but when I checked the index using Luke, classA.classB.description in the index wasn't updated, and the data cannot be searchable by keyword "anotherStr", but can be searchable by

Avoid Circular Dependency

て烟熏妆下的殇ゞ 提交于 2019-12-21 02:28:17
问题 I am developing a travel management application. The design in question is something like following : Each person in a tour is designated as a Traveler. Each Traveler has a Passport. Now, a Traveler can be a MainMember or a SubMember, depending on whether or not he is the head of the family. A MainMember decides stuff like TourPackage, total amount for his travelling family, etc. A SubMember is dependent on the MainMember while travelling. So, if a MainMember is deleted, all its SubMembers

How to add data of different records to a single record?

限于喜欢 提交于 2019-12-20 22:00:04
问题 If do not have time please have a look at the example I have two types of users, temporary users and permanent users. Temporary users use the system as guest just provide their name and use it but system needs to track them. Permanent users are those that are registered and permanent. Once user create a permanent record for himself, I need to copy all the information that has been tracked while user was a guest to his permanent record. Classes are as following, @Entity public class PermUser{

How to avoid creating a new row if similar row exists?

风格不统一 提交于 2019-12-20 12:15:56
问题 I need to configure hibernate to avoid creating duplicate rows, (although the row exists it creates a new one, and since only one filed is set it set all the rest to NULL) Lets say I have a row as following id des index age 1 MyName 2 23 Although I just set MyName as des and it already exists in the Name table hibernate create a new row as following id des index age 1 MyName 2 23 2 MyName Null Null << new row with null values will be created rather than updating the previous one When I want

Unique Constraint Over Multiple Columns

梦想与她 提交于 2019-12-20 10:17:15
问题 I am using SEAM 2/Hibernate along with PostgreSQL 9 database. I have the following table Active Band =========== active_band_id serial active_band_user text active_band_date timestamp active_band_process integer I would like to add a constraint that ensures each new entry has a unique combination of active_band_user and active_band_date. There could potentially be many attempted inserts per second so I need this to be as efficient as possible, is there a SEAM / hibernate annotation I can use