-->
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.  [ 1 post ] 
Author Message
 Post subject: New2Hibernate:How would look like these tables in Hibernate?
PostPosted: Sun Apr 11, 2010 7:30 am 
Newbie

Joined: Sun Apr 11, 2010 7:22 am
Posts: 4
I have created a simple application using simple old JDBC, but I would like to see how the application would look like using Hibernate, but I don't know how to put the sql code in java. I have found LOTS of examples, but I'm pretty much confused about using Hibernate and I don't know If I made such a good joob.

For example, for these tables:

AUTHOR table

* Author_ID, PK
* First_Name
* Last_Name

TITLES table

* TITLE_ID, PK
* NAME
* Author_ID, FK

TITLES table

* DOMAIN_ID, PK
* NAME
* TITLE_ID, FK

My version :) :

AUTHOR table
Code:
@Entity
    @Table(name = "AUTHORS", schema = "LIBRARY")
    public class Author{
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "Author_ID")
        private int authorId;
        @Column(name = "First_Name", nullable = false, length = 50)
        private String firstName;
        @Column(name = "Last_Name", nullable = false, length = 40)
        private String lastName;
        @OneToMany
        @JoinColumn(name = "Title_ID")
        private List<Title> titles;

TITLES table[/size]
Code:
@Entity
@Table(name = "TITLES")
public class Title{

    @Id
    @Column(name = "Title_ID")
    private int titleID;
    @Column(name = "Name", nullable = false, length = 50)
    private String name;
    @ManyToOne
    @JoinColumn(name = "Domain_ID")
    private Domain domains;


TITLES table
Code:
@Entity
@Table(name = "DOMAINS")
public class Domain{
      @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "Domain_ID")
        private int Domain_ID;
        @Column(name = "Name", nullable = false, length = 50)
        private String name;
        @OneToOne(mappedBy = "domains")
        private Title title;
}


I don't think I made such a good job, especially for connecting the tables...
Any comments? :)


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

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.