Code:
public enum GameType{Ludo,Chess,Trivial,Monopoly,Checkers}
public class Ranking {
private GameType game;
private int wonGames;
private int lostGames;
}
public class User {
private String username;
private String password;
private String email;
private String name;
private String lastName;
private String secondLastName;
private List<String> friends;
private List<Ranking> rankings;
}
I have this java classes and I want to map them with Hibernate and xml mapping files but I have some troubles with the rankings. How can I map these clasess? This is what I tried:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 26-feb-2012 15:10:29 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="ProductLine.User" table="USER">
<id name="username" type="java.lang.String">
<column name="USERNAME" />
<generator class="assigned" />
</id>
<property generated="never" lazy="false" name="password"
type="java.lang.String">
<column name="PASSWORD" />
</property>
<property generated="never" lazy="false" name="email"
type="java.lang.String">
<column name="EMAIL" />
</property>
<property column="ROLE" generated="never" lazy="false" name="role"
not-null="true">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">ProductLine.RoleType</param>
<param name="type">12</param>
</type>
</property>
<property generated="never" lazy="false" name="name"
type="java.lang.String">
<column name="NAME" />
</property>
<property generated="never" lazy="false" name="lastName"
type="java.lang.String">
<column name="LASTNAME" />
</property>
<property generated="never" lazy="false" name="secondLastName"
type="java.lang.String">
<column name="LAST_NAME" />
</property>
<set name="rankings" sort="unsorted" table="RANKINGS">
<key column="username" />
<many-to-many class="ProductLine.Ranking" column="game" unique="true" />
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 24-abr-2012 18:37:50 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="ProductLine.Ranking" table="RANKINGS">
<id column="game" name="id">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">ProductLine.GameType</param>
<param name="type">12</param>
</type>
<generator class="assigned" />
</id>
<property generated="never" lazy="false" name="wonGames"
type="int">
<column name="WONGAMES" />
</property>
<property generated="never" lazy="false" name="lostGames"
type="int">
<column name="LOSTGAMES" />
</property>
</class>
</hibernate-mapping>
I have the following databse in MYSQL
What I must change to do the correct mapping? Thanks