Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Postgre pocetnik

[es] :: PostgreSQL :: Postgre pocetnik

[ Pregleda: 4010 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

cope.rs
Predrag Stojadinović
preff.net
Aachen

Član broj: 145487
Poruke: 145
*.pools.arcor-ip.net.

Sajt: www.prefko.com


Profil

icon Postgre pocetnik15.05.2007. u 23:23 - pre 185 meseci
Pozdrav svima. Desila mi se GenericJDBCException greska sa PostgreSQL bazom.

Svi podaci su ispod, ima li neko ideju o cemu se radi?

Naime, napravio sam applet za igranje Preferansa i sinoc dok smo ga testirali tri sata je sve radilo kako treba. Onda, odjednom, na sasvim obicnom brisanju jednog reda iz jedne tabele desila se sledeca greska:

Code:

Exception in thread "Thread-5" org.hibernate.exception.GenericJDBCException: Cannot open connection
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)
        at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
        at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
        at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
        at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
        at $Proxy0.beginTransaction(Unknown Source)
        at cope.pref.hibernate.util.HibernateUtil.createCriteria(Unknown Source)
        at cope.pref.balkan.room.db.RoomDBUtil$1.run(Unknown Source)
        at cope.pref.balkan.room.db.RoomDBUtil.playerLeftRoom(Unknown Source)
        at cope.pref.balkan.room.PrefRoom.leftRoom(Unknown Source)
        at cope.pref.balkan.room.PrefRoom.receiveRoomClientEvent(Unknown Source)
        at cope.pref.balkan.room.net.RoomServer.fireRoomClientEvent(Unknown Source)
        at cope.pref.balkan.room.net.RoomServer.run(Unknown Source)

Caused by: java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.InterruptedException
        at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
        at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
        at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:62)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:531)
        at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
        at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)
        ... 16 more


Caused by: java.lang.InterruptedException
        at java.lang.Object.wait(Native Method)
        at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1315)
        at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
        ... 19 more

=================================================================================================
Metod gde se greska desila je:
Code:

    public static void playerLeftRoom(final String username)
    {
        Runnable runnable = new Runnable()
        {
            public void run()
            {
                Criteria crit = HibernateUtil.createCriteria(RoomUser.class);
                crit.setFetchMode("user", FetchMode.DEFAULT);
                crit.createCriteria("user", "user");
                crit.add(Expression.eq("user.username", username));
                List list = crit.list();
                for (Object object : list)
                {
                    if (object instanceof RoomUser)
                    {
                        RoomUser dbRoomUser = (RoomUser) object;
                        HibernateUtil.delete(dbRoomUser);
                    }
                }
                HibernateUtil.closeSession();
            }
        };
        runnable.run();
    }

=================================================================================================
A klasa HibernateUtil je:
Code:

package cope.pref.hibernate.util;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.beans.PropertyVetoException;
import java.io.ByteArrayOutputStream;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Expression;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public final class HibernateUtil
{
    private static SessionFactory    sessionFactory    = null;

    private static final String        DRIVER            = "org.postgresql.Driver";
    private static final String        JDBC_URL        = "jdbc:postgresql://localhost:5432/preferans";
    private static final String        USER            ...
    private static final String        PASSWORD        ...

    static
    {
        init();
    }

    public static Object load(Class cls, Long id)
    {
        final Session session = HibernateUtil.getSession();
        session.beginTransaction();
        final Object obj = session.load(cls, id);
        session.getTransaction().commit();
        return obj;
    }

    public static void delete(Object obj)
    {
        final Session session = getSession();
        session.beginTransaction();
        session.delete(obj);
        session.getTransaction().commit();
    }

    public static void save(Object obj)
    {
        final Session session = getSession();
        session.beginTransaction();
        session.save(obj);
        session.getTransaction().commit();
    }

    public static void saveOrUpdate(Object obj)
    {
        final Session session = getSession();
        session.beginTransaction();
        session.saveOrUpdate(obj);
        session.getTransaction().commit();
    }

    public static void update(Object obj)
    {
        final Session session = getSession();
        session.beginTransaction();
        session.update(obj);
        session.getTransaction().commit();
    }

    public static Criteria createCriteria(Class cls)
    {
        if (sessionFactory.isClosed()) init();
        Session session = sessionFactory.getCurrentSession();
        session.beginTransaction();
        return session.createCriteria(cls);
    }

    public static Session getSession()
    {
        if (sessionFactory.isClosed()) init();
        return sessionFactory.getCurrentSession();
    }

    public static void closeSession()
    {
        if (!sessionFactory.isClosed())
        {
            Session session = sessionFactory.getCurrentSession();
            // session.flush();
            session.disconnect();
            session.close();
            sessionFactory.close();
        }
    }

    public static void init()
    {
        try
        {
            final ComboPooledDataSource cpds = new ComboPooledDataSource();
            cpds.setDriverClass(DRIVER);
            cpds.setJdbcUrl(JDBC_URL);
            cpds.setUser(USER);
            cpds.setPassword(PASSWORD);
            // cpds.setMaxStatements(180);
            // cpds.setMaxStatementsPerConnection(180);

            sessionFactory = new Configuration().configure().buildSessionFactory();
        }
        catch (final PropertyVetoException e)
        {
            e.printStackTrace();
            throw new ExceptionInInitializerError(e);
        }
    }

    public static Object getByColumnValue(Class className, String column, String value)
    {
        final Session session = getSession();
        session.beginTransaction();
        Criteria crit = session.createCriteria(className);
        crit.add(Expression.eq(column, value));
        List res = crit.list();

        for (Object obj : res)
            return obj;

        return null;
    }

    public static byte[] stringToBytes(String string)
    {
        return string.getBytes();
    }

    public static String bytesToString(byte[] data)
    {
        return new String(data);
    }

    public static byte[] imageToBytes(Image image)
    {
        try
        {
            BufferedImage buffImg = new BufferedImage(image.getWidth(null), image.getHeight(null),
                    BufferedImage.TYPE_INT_RGB);

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ImageIO.write(buffImg, "gif", bos);

            return bos.toByteArray();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    public static Image bytesToImage(byte[] data)
    {
        ImageIcon imageIcon = new ImageIcon(data);
        return imageIcon.getImage();
    }

}

Pedja
- http://www.CoPe.rs
- http://iKr.me - GROK! SKRATI TAJ LINK!
 
Odgovor na temu

cope.rs
Predrag Stojadinović
preff.net
Aachen

Član broj: 145487
Poruke: 145
*.arena-medien.net.

Sajt: www.prefko.com


Profil

icon Re: Postgre pocetnik16.05.2007. u 14:20 - pre 185 meseci
Zaboravih da postavim hibernate.cfg.xml fajl:
Code:

<?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">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.url">jdbc:postgresql://localhost:5432/preferans</property>
        <property name="connection.username">...</property>
        <property name="connection.password">...</property>

        <!-- configuration pool via c3p0--> 
        <property name="hibernate.c3p0.acquire_increment">1</property>
        <property name="hibernate.c3p0.idle_test_period">100</property> <!-- seconds -->

        <!-- C3P0 connection pool timeout -->
        <property name="hibernate.c3p0.timeout">100</property> <!-- seconds -->

        <!-- C3P0 connection pool minimum size-->
        <property name="hibernate.c3p0.min_size">1</property>

        <!-- C3P0 connection pool maximum size-->
        <property name="hibernate.c3p0.max_size">100</property>

        <!-- C3P0 connection pool maximum statements -->
        <property name="hibernate.c3p0.max_statements">0</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <!-- <property name="show_sql">true</property> -->

        <!-- Drop and re-create the database schema on startup -->
        <!-- <property name="hbm2ddl.auto">create</property> -->

        <mapping resource="cope/pref/hibernate/tables/Tables.hbm.xml"/>
        <mapping resource="cope/pref/hibernate/tables/GameTables.hbm.xml"/>
        <mapping resource="cope/pref/hibernate/tables/TypeTables.hbm.xml"/>

    </session-factory>

</hibernate-configuration>

Pedja
- http://www.CoPe.rs
- http://iKr.me - GROK! SKRATI TAJ LINK!
 
Odgovor na temu

chachka
Srđan Mijatov
Programer
BUS Computers
Kikinda

Član broj: 53780
Poruke: 576
*.suonline.net.

Sajt: www.baze-podataka.net


+4 Profil

icon Re: Postgre pocetnik17.05.2007. u 08:15 - pre 185 meseci
Meni ovo vise deluje kao tema za Java forum. Moderatore?
"The best code is no code at all."
- Zidar (ES član)
"Biggest obstacle to learning
SQL is unlearning procedural
programming."
- Joe
Celko
"Minimize code, maximize data."
- A. Neil Pappalardo
 
Odgovor na temu

cope.rs
Predrag Stojadinović
preff.net
Aachen

Član broj: 145487
Poruke: 145
*.pools.arcor-ip.net.

Sajt: www.prefko.com


Profil

icon Re: Postgre pocetnik17.05.2007. u 10:39 - pre 185 meseci
pazi, po onome sto sam procitao ovde:

http://www.ashtech.net/~syntax...eSQL-Require-Transactions.html

moguce da je tema stvarno vise za Java/Hibernate nego za Postgre.

U tom slucaju izvinjavam se, ali posto sam stvarno VOONA za baze, mislio sam da je do postgre-a.
Pedja
- http://www.CoPe.rs
- http://iKr.me - GROK! SKRATI TAJ LINK!
 
Odgovor na temu

[es] :: PostgreSQL :: Postgre pocetnik

[ Pregleda: 4010 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.