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.  [ 4 posts ] 
Author Message
 Post subject: new in hibernate
PostPosted: Fri Jan 12, 2007 2:18 am 
Newbie

Joined: Thu Jan 11, 2007 9:23 am
Posts: 5
hi all,
I am new in hibernate, can anyone told me
1) why I got error
on [b]Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at test.InsertProduct.main(InsertProduct.java:18)[/b]

[code]package test;
import org.hibernate.cfg.Configuration;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import test.hibernate.Order;
import test.hibernate.OrderItem;
import test.hibernate.Product;
public class InsertProduct {

public static void main(String[] args)
throws Exception {

// 1. Build a Product
Product p = new Product();
p.setName(args[0]);
p.setAmount(Integer.parseInt(args[1]));
p.setPrice(Double.parseDouble(args[2]));

// 2. Fire up Hibernate
Configuration cfg = new Configuration()
.addClass(Product.class);
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

System.out.println(p);
// 3. Open Session
Session sess = sessionFactory .openSession();

// 4. Save Product and close Session
Transaction t = sess.beginTransaction();
sess.save(p);
t.commit();
sess.close();
System.out.println(p);
}
}[/code]
in xml I have
<id name="id" type="string" unsaved-value="null" >
<column name="id" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
2) what is the find in here . I use Mysql
[code]Session sess = sf.openSession();
// make sure you have milk and coffee in your db
Product milk = (Product) sess.[b]find[/b](query, "Milk", Hibernate.STRING).get(0);
Product coffee = (Product) sess.[b]find[/b](query, "Coffee", Hibernate.STRING).get(0);
sess.close();[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 12, 2007 10:17 am 
Newbie

Joined: Thu Jan 11, 2007 9:23 am
Posts: 5
any hibernate tutorial ??
thank you


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 12, 2007 12:18 pm 
Newbie

Joined: Sun Apr 04, 2004 4:22 am
Posts: 7
When you run the code you should supply 3 arguments.

Code:
java InsertProduct arg1 arg2 arg3


Did you? And what were they?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 14, 2007 9:58 pm 
Newbie

Joined: Thu Jan 11, 2007 9:23 am
Posts: 5
Thank you fro the reply,
I just read the tutorial and try to run the example,
like the example on
http://www.hibernate.org/hib_docs/v3/re ... orial.html

package events;
[code]import org.hibernate.Session;

import java.util.Date;

import util.HibernateUtil;

public class EventManager {

[b]public static void main(String[] args) {
EventManager mgr = new EventManager();

if (args[0].equals("store")) {
mgr.createAndStoreEvent("My Event", new Date());
}

HibernateUtil.getSessionFactory().close();
}[/b]
private void createAndStoreEvent(String title, Date theDate) {

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

Event theEvent = new Event();
theEvent.setTitle(title);
theEvent.setDate(theDate);

session.save(theEvent);

session.getTransaction().commit();
}

}[/code]
i don't understand the code in bode
what they try to do on this few lins of code??
if (args[0].equals("store")) {
mgr.createAndStoreEvent("My Event", new Date());
}
and it also couse out of index error.
what is wrong?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.