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

Hibernate problem

[es] :: Java :: Hibernate problem

[ Pregleda: 2560 | Odgovora: 10 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

umpirsky
Saša Stamenković
Niš

Član broj: 160299
Poruke: 65
*.dynamic.sbb.rs.

Sajt: umpirsky.com


Profil

icon Hibernate problem21.09.2008. u 21:14 - pre 189 meseci
Imam sledeći prolblem:

Ova linija koda

Code:

sessionFactory = new Configuration().configure(HIBERNATE_CONFIG).buildSessionFactory();


štampa ovo:

Code:

21.09.2008. 21.40.59 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.6
21.09.2008. 21.40.59 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
21.09.2008. 21.40.59 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
21.09.2008. 21.40.59 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
21.09.2008. 21.40.59 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: model/hibernate/hibernate.cfg.xml
21.09.2008. 21.40.59 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: model/hibernate/hibernate.cfg.xml
21.09.2008. 21.40.59 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : model/hibernate/Country.hbm.xml
21.09.2008. 21.40.59 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: model.hibernate.Country -> country
21.09.2008. 21.40.59 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : model/hibernate/Airport.hbm.xml
21.09.2008. 21.40.59 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: model.hibernate.Airport -> airport
21.09.2008. 21.40.59 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : model/hibernate/Flight.hbm.xml
21.09.2008. 21.40.59 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: model.hibernate.Flight -> flight
21.09.2008. 21.41.00 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : model/hibernate/Ticket.hbm.xml
21.09.2008. 21.41.00 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: model.hibernate.Ticket -> ticket
21.09.2008. 21.41.00 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : model/hibernate/Airplane.hbm.xml
21.09.2008. 21.41.00 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: model.hibernate.Airplane -> airplane
21.09.2008. 21.41.00 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
21.09.2008. 21.41.00 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: model.hibernate.Airport.flightsForToId -> flight
21.09.2008. 21.41.00 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: model.hibernate.Airport.flightsForFromId -> flight
21.09.2008. 21.41.00 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: model.hibernate.Flight.ticketsForReturningId -> ticket
21.09.2008. 21.41.00 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: model.hibernate.Flight.ticketsForDepartureId -> ticket
21.09.2008. 21.41.00 org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: model.hibernate.Airplane.flights -> flight
21.09.2008. 21.41.00 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
21.09.2008. 21.41.00 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
21.09.2008. 21.41.00 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
21.09.2008. 21.41.00 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost/sat
21.09.2008. 21.41.00 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=umpirsky, password=****}
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.0.51b-community-nt
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.5 ( Revision: ${svn.Revision} )
21.09.2008. 21.41.00 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
21.09.2008. 21.41.00 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
21.09.2008. 21.41.00 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
21.09.2008. 21.41.00 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
21.09.2008. 21.41.00 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
21.09.2008. 21.41.00 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
21.09.2008. 21.41.01 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
21.09.2008. 21.41.01 org.hibernate.impl.SessionFactoryImpl close
INFO: closing
21.09.2008. 21.41.01 org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:mysql://localhost/sat
21.09.2008. 21.41.03 org.hibernate.impl.SessionFactoryImpl close
INFO: closing
21.09.2008. 21.41.03 org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:mysql://localhost/sat
21.09.2008. 21.41.03 org.hibernate.impl.SessionFactoryImpl close
INFO: closing
21.09.2008. 21.41.03 org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:mysql://localhost/sat
21.09.2008. 21.41.03 org.hibernate.impl.SessionFactoryImpl close
INFO: closing
21.09.2008. 21.41.03 org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:mysql://localhost/sat


hibernate.cfg.xml izgleda ovako

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>
        <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="hibernate.connection.password">*******</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/sat</property>
        <property name="hibernate.connection.username">user</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
        <mapping resource="model/hibernate/Country.hbm.xml" />
        <mapping resource="model/hibernate/Airport.hbm.xml" />
        <mapping resource="model/hibernate/Flight.hbm.xml" />
        <mapping resource="model/hibernate/Ticket.hbm.xml" />
    </session-factory>
</hibernate-configuration>


Inače sve radi onako kako očekujem, čitam iz baze podatke bez problema, ali dobijam ovaj log u konzoli.
U čemu je problem?
 
Odgovor na temu

spartanac86
student
Jugoistocna Srbija

Član broj: 178865
Poruke: 93
*.adsl.beotel.net.



Profil

icon Re: Hibernate problem22.09.2008. u 21:16 - pre 189 meseci
pa ako sve radi, onda problema uopste i nema :)
ne ozbiljno, s obzirom da je u log sve pod "INFO" i da nema upozorenja itd, znaci da bi sve trebalo da radi kako treba. projektanti klase su napravili tako da se stampaju te informacije na konzolu radi lakseg eventualnog debugovanja i to je to. my 2 cents
 
Odgovor na temu

umpirsky
Saša Stamenković
Niš

Član broj: 160299
Poruke: 65
*.dynamic.sbb.rs.

Sajt: umpirsky.com


Profil

icon Re: Hibernate problem22.09.2008. u 21:31 - pre 189 meseci
Ovako koristim hibernate:

Code:

public static String[] getCountryNames() {
        List<String> countries = null;

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

        try {
            session.beginTransaction();

            countries = session.createCriteria(Country.class)
                .setProjection(Projections.property("name"))
                .list();

            session.getTransaction().commit();
        } catch (Throwable e) {
            // TODO
            System.out.println(e.getMessage());
            e.printStackTrace();
        } finally {
            session.close();
        }

        return (String[])countries.toArray(new String[countries.size()]);
    }


Do sada nisam komitovao transakciju, pa zato nije bilo gresaka.

Kada uradim:

Code:

session.getTransaction().commit();


dobijem:

Code:

org.hibernate.SessionException: Session was already closed
    at org.hibernate.impl.SessionImpl.close(SessionImpl.java:275)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
    at $Proxy0.close(Unknown Source)
    at sapi.SCountry.getCountryNames(SCountry.java:44)
    at gui.NewFlightDialog.initGUI(NewFlightDialog.java:109)
    at gui.NewFlightDialog.<init>(NewFlightDialog.java:74)
    at gui.SatSwing.showNewFlightDialog(SatSwing.java:177)
    at gui.SatSwing.access$0(SatSwing.java:176)
    at gui.SatSwing$2.actionPerformed(SatSwing.java:88)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.AbstractButton.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)


I usput, da li je dobra ova f-ja, koliko vidim u manualu, ovo je antipatern, uglavnom zbog exception handlinga, koji treba da se hvata na visim nivoima, ili sam nesto pogresno razumeo.
 
Odgovor na temu

Dr NIK
Novakovic Marko
BG

Član broj: 19744
Poruke: 132
*.dynamic.sbb.rs.

Sajt: www.mnovakovic.info


+1 Profil

icon Re: Hibernate problem23.09.2008. u 14:23 - pre 189 meseci
Prvo i prvo, ja bih ti preporucio da koristis neki DI framework za ovo, recimo spring.

Tu nemas potrebe da imas transaction.begin() i commit(), nego samo anotiras metodu sa @Transactional i sve radi.

Takodje, zasto bi zatvarao sesiju? Ti dobijas getCurrentSession koja bi trebala da bude otvorena tokom celog izvrsavanja programa?

mozes da uradis HibernateUtil.getSessionFactory().openSession(); (valjda se tako zove metoda)

takodje, ovako radi sa transakcijama ako vec moras rucno. (EDIT: onaj tvoj nacin je za currentSession(), u tom slucaju ne trabas da imas finally za session.close())

Transaction tx = null;
try {
tx = session.beginTransaction();

// do some work
...

tx.commit();
}

session.beginTransaction() ti vraca transaction objekat i nad njim radis commit().
 
Odgovor na temu

umpirsky
Saša Stamenković
Niš

Član broj: 160299
Poruke: 65
212.200.237.*

Sajt: umpirsky.com


Profil

icon Re: Hibernate problem23.09.2008. u 15:05 - pre 189 meseci
O.K. Hvala, znao sam da nisam izabrao najsrecnije resenje, prvi put se srecem sa hibernate, pa mi je spring pride dodatno opterecenje.

Ovo je demo aplikacija koja mi sluzi da se upoznam sa hibernate, to je swing aplikacija, ne znam kako da je organizujem da mi sesija bude ovorena svo vreme, i da ne moram stalno da getCurrentSession, beginTransaction ...

Sesija se otvara samo jednom, zato sto je ovo singlton :

Code:

public class HibernateUtil {

    private static SessionFactory sessionFactory = null;
    private static final String HIBERNATE_CONFIG = "model/hibernate/hibernate.cfg.xml";

    private static void loadSession() throws Exception {
        if (null == sessionFactory) {
            try {
                sessionFactory = new Configuration().configure(HIBERNATE_CONFIG).buildSessionFactory();
            } catch (Exception e) {
                throw e;
            }
        }
    }

    public static SessionFactory getSessionFactory() {
        try {
            loadSession();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return sessionFactory;
    }

}

 
Odgovor na temu

Dr NIK
Novakovic Marko
BG

Član broj: 19744
Poruke: 132
*.dynamic.sbb.rs.

Sajt: www.mnovakovic.info


+1 Profil

icon Re: Hibernate problem23.09.2008. u 15:51 - pre 189 meseci
getSsessionFactory() ti je singleton. Ti iz njega vadis ili getCurrentSession() ili openSession()

ovo getCurrentSession() ti znaci da dobijas trenutno aktivnu sesiju (za taj thread) i nju nikad nemoj da zatvaras. (Pretpostavljam da ti getCurrentSession() ne vraca null)
A ovo openSession() ide u paru sa close() u finally bloku, dakle za jednokratnu upotrebu. Inace swing i hibernate su malo zapetljani, bas zbog tog vise-thread okruzenja..

Jesi li isprobao nesto od ovoga? Jel ti radi?

 
Odgovor na temu

umpirsky
Saša Stamenković
Niš

Član broj: 160299
Poruke: 65
*.dynamic.sbb.rs.

Sajt: umpirsky.com


Profil

icon Re: Hibernate problem23.09.2008. u 19:09 - pre 189 meseci
Upravo tako, i ne vraca null.

Procitaj prethodne postove, radi sa info logovima, ako ne radim session.getTransaction().commit(); (commit transakcije), kad probam da je komitujem (mada ne znam da li je to neophodno pri citanju, dobijam exception

Code:

org.hibernate.SessionException: Session was already closed
    at org.hibernate.impl.SessionImpl.close(SessionImpl.java:275)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
    at $Proxy0.close(Unknown Source)
    at sapi.SCountry.getCountryNames(SCountry.java:44)
    at gui.NewFlightDialog.initGUI(NewFlightDialog.java:109)
    at gui.NewFlightDialog.<init>(NewFlightDialog.java:74)
    at gui.SatSwing.showNewFlightDialog(SatSwing.java:177)
    at gui.SatSwing.access$0(SatSwing.java:176)
    at gui.SatSwing$2.actionPerformed(SatSwing.java:88)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.AbstractButton.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)


Sad se i ponavljam :P to je u stvari razlog zasto sam otvorio temu, da resim ovaj problem.
Cudno je da kad sam nedavno radio nesto sa GWT-EXTom, nisam imao ovakvih problema sa hibernateom, a cini mi se da sam isto postavio okruzenje...mora da negde gresim.

Hvala na interesovanju za temu.
 
Odgovor na temu

umpirsky
Saša Stamenković
Niš

Član broj: 160299
Poruke: 65
*.dynamic.sbb.rs.

Sajt: umpirsky.com


Profil

icon Re: Hibernate problem23.09.2008. u 20:27 - pre 189 meseci
BTW, ovo:

Code:

Transaction tx = null;
try {
tx = session.beginTransaction();

// do some work
...

tx.commit();
}


je ekvivalentno sa ovim:

Code:

try {
session.beginTransaction();

// do some work
...

session.getTransaction().commit();
}


Zato sto API kaze:

Transaction getTransaction()
Get the Transaction instance associated with this session. The class of the returned Transaction object is determined by the property hibernate.transaction_factory.

ne moram transakciju da drzim u posebnoj promenljivoj, zar ne?

Tako izgleda da sa transakcijama radim kako treba, ne zna zasto mi se javlja ovaj exception?
 
Odgovor na temu

umpirsky
Saša Stamenković
Niš

Član broj: 160299
Poruke: 65
*.dynamic.sbb.rs.

Sajt: umpirsky.com


Profil

icon Re: Hibernate problem23.09.2008. u 20:57 - pre 189 meseci
Izgleda da nisam jedini http://forum.hibernate.org/viewtopic.php?p=2373373

Mada, i dalje nemam resenje.
 
Odgovor na temu

Dr NIK
Novakovic Marko
BG

Član broj: 19744
Poruke: 132
194.106.175.*

Sajt: www.mnovakovic.info


+1 Profil

icon Re: Hibernate problem23.09.2008. u 21:59 - pre 189 meseci
Tek sada vidim da ti ni anotacije ne koristis, vec mapping XML-ove...

To ti je malo staro da ti kazem iskreno, i trebao bi da izbegnes to.

A bas zbog ovih stvari tipa podesavanje property-a hibernate.transaction_factory (koji ti nisi podesio koliko vidim) ti predlazem da koristis spring... On ti tu sam obezbedi mnoge stvari (recimo @Transactional anotacija kojom anotiras metodu i cime obezbedjujes transakciju te metode vrlo elegantno).

Provaljivanje svega u startu bi ti samo zakomplikovalo stvari ako si pocetnik, a mnogo je lakse resavati probleme kao te sto ti imas kada imas vec iskustva u radu sa necime, pa imas i veliku sliku. Imas knjigu MANNING- Spring in action, imas celo poglavlje o hibernate-u.

Elem, da ne smaram, jesi li provalio foru sa getCurrentSession() i openSession() koja je razlika? Probaj da izbrises ono session.close() ako ides getCurrentSession() ili otvori novu sesiju pa je zatvaraj na kraju.

Jesi li probao te kombinacuje? Mozda da vidis ovaj hibernate.transaction_factory cime bi mogao da popunis - koji je default?
 
Odgovor na temu

umpirsky
Saša Stamenković
Niš

Član broj: 160299
Poruke: 65
212.200.237.*

Sajt: umpirsky.com


Profil

icon Re: Hibernate problem24.09.2008. u 07:06 - pre 189 meseci
Ubedio si me, pogledacu Spring.

Ali cu isto tako pokusati da ustanovim u cemu je problem, jer mislim da je bitno da razumem i na ovom "niskom" nivou.

Hvala na odgovorima.
 
Odgovor na temu

[es] :: Java :: Hibernate problem

[ Pregleda: 2560 | Odgovora: 10 ] > FB > Twit

Postavi temu Odgovori

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