-->
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: Insert tuples
PostPosted: Wed Jul 01, 2009 2:13 am 
Newbie

Joined: Tue Jun 30, 2009 4:39 am
Posts: 1
Hello,

I'am a using hibernate for the first time in my application, so I have no experience in using hibernate.
I did the tutorial [url]1.2.Part 1 - The first Hibernate Application[/url] and it works fine, the tables become created (Person - Person_Event - Event -> m:n connetion)

So my question is, how can I fill the tables, is it the best way first to insert a person with code 3., than to insert an event with code 2. and than to connect this two with code 1..

Is that the best way in this case (m:n) to insert a tuple.

Thanks for the answers,
All the best,
Michael

1.
Code:
Long eventId = mgr.createAndStoreEvent("My Event");
Long personId = mgr.createAndStorePerson("Foo", "Bar");
mgr.addPersonToEvent(personId, eventId);
System.out.println("Added person " + personId + " to event " + eventId);


2.
Code:
private Long createAndStoreEvent(String title) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Connection theEvent = new Connection();
        theEvent.setConnectionName(title);
        session.save(theEvent);
        session.getTransaction().commit();
        return theEvent.getId();
        }


3.
Code:

    private Long createAndStorePerson(String firstname, String lastname) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        MappingPool thePerson = new MappingPool();
        thePerson.setName(firstname);
        thePerson.setZustand(lastname);
        session.save(thePerson);
        session.getTransaction().commit();
        return thePerson.getId();
        }


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.