-->
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: Configuration Hibernate with postgresql on linux
PostPosted: Fri Mar 17, 2006 2:17 pm 
Newbie

Joined: Fri Mar 17, 2006 2:04 pm
Posts: 2
Hello all !!!
I used hibernate 3.0 with postgresql on linux
this is my configuration file : hibernate.cfg.xml
//////////////////////
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name="myeclipse.connection.profile">postgresConnection</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/myDB</property>
<property name="connection.username">postgres</property>
<property name="connection.password"></property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<mapping resource="com/university/dto/Account.hbm.xml" />
</session-factory>

</hibernate-configuration>
////////////////////////////////////////////

and this is my client test program :

package com.university.test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.university.dto.Account;

public class ClientTest {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Session session = null;
Transaction tx = null;
System.out.println("begin create!!!");

try{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
//session = HibernateSessionFactory.currentSession();
//tx = session.beginTransaction();
System.out.println("insert record");
Account account = new Account();
account.setId(new Integer(3));
account.setUsername("Dai");
account.setPassword("chau83");
System.out.println("completed fill account object!!!");
session.save(account);
//session.saveOrUpdate(account);
System.out.println("done!!!");

}catch(Exception e){
System.out.println(e.getMessage());
}finally{
//tx.commit();
session.flush();
session.close();
}
}

}
//////////////////////////
and i always receive this error : Cannot open connection.

anybody helps me to fix this error, thanks for your help.


Top
 Profile  
 
 Post subject: connection configuration
PostPosted: Fri Mar 17, 2006 4:24 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Does Postgress accepts IP connections at all? ( -i option enabled)

Does pg_hba.conf allows IP connection from localhost with using password authentication?

Can you connect to your DB with using straight JDBC and the same db url and credentials?

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Hi
PostPosted: Sat Mar 18, 2006 9:56 am 
Newbie

Joined: Fri Mar 17, 2006 2:04 pm
Posts: 2
Yes, i cofigured this file pd_hba.conf already, allowing ip address locahost is 127.0.0.1, and i can connect to my DB using JDBC.

I don't know why, please help me.

thanks a lot..


Top
 Profile  
 
 Post subject: Re: Configuration Hibernate with postgresql on linux
PostPosted: Sat Mar 18, 2006 11:05 am 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
Hello Friend:

I have PostgreSQL configured. I guess your problem is ocurred because you are not star your Data Base service.

You have to start your service:

service postgresql start;

Than, create your database, as you write: createdb MyDB, and so on.

But, If i was not wrong, your configuration has a problem at the line
jdbc:postgresql://localhost:5432/myDB

I have configured Hibernate in my Linux, and that run well when the hibernate configuration file wrote: jdbc:postgresql:myDB.

Thats possible activate Hibernate with that configuration, you can try it.

Ah... I forgot: you have to put your eye at the line where specific your login and password to login PostgreSQL Data base.

That is importante.

I speak bad english, so i am sorry....

Rigard.

Neketsu Shonen


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.