-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How can I map these java classes with Hibernate?
PostPosted: Sun Apr 29, 2012 10:20 am 
Newbie

Joined: Sun Apr 29, 2012 10:02 am
Posts: 2
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

Image

What I must change to do the correct mapping? Thanks


Top
 Profile  
 
 Post subject: Re: How can I map these java classes with Hibernate?
PostPosted: Mon Apr 30, 2012 6:21 am 
Newbie

Joined: Sun Apr 29, 2012 10:02 am
Posts: 2
No one can help me please?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.