How can I do it manually?
For example: I have a "DataProvider" class with a method:
public static Administrator getAdministrator(Integer id) {
Administrator administrator= (Administrator)
HibernateUtil.getSessionFactory().getCurrentSession().createCriteria(Administrator.class).add(Property.forName("id").eq(id)).uniqueResult();
return administrator;
}
I get the error message. How shall I modify the code?
I tried it with Transaction tx = ... and then tx.begin() tx.commit() -- but
then suddenly hibernate tries permanently to update an object... wired !
----- Ursprüngliche Mail ----
Von: Pieter Degraeuwe <[email protected]>
An: [email protected]
Gesendet: Dienstag, den 6. Oktober 2009, 09:29:58 Uhr
Betreff: Re: org.hibernate.HibernateException: createCriteria is not valid
without active transaction
You did not setup your transactions properly.
Or you start your transaction manually, or if you like spring, you can let
spring manage it. (just add your transction annotations to your services,
and, done !
On Tue, Oct 6, 2009 at 9:15 AM, Peter Arnulf Lustig <[email protected]>wrote:
> get this error always! I don't understand why.
>
> this is my hibernate.cfg.xml
>
>
> <hibernate-configuration>
> <session-factory name="session1">
> <property
> name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
> <property
> name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
> <property
> name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb</property>
> <property name="hibernate.connection.username">root</property>
> <property
> name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
> <mapping resource="org/omikron/test/data/Ticket.hbm.xml"/>
> <mapping resource="org/omikron/test/data/Testprocedure.hbm.xml"/>
> <mapping resource="org/omikron/test/data/Tag.hbm.xml"/>
> <mapping resource="org/omikron/test/data/Testentity.hbm.xml"/>
> <mapping resource="org/omikron/test/data/Questionset.hbm.xml"/>
> <mapping resource="org/omikron/test/data/Administrator.hbm.xml"/>
> <mapping resource="org/omikron/test/data/Systemsetting.hbm.xml"/>
> <mapping resource="org/omikron/test/data/Question.hbm.xml"/>
> </session-factory>
> </hibernate-configuration>
>
>
>
> Do you have an idea?
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
--
Pieter Degraeuwe
Systemworks bvba
Belgiëlaan 61
9070 Destelbergen
GSM: +32 (0)485/68.60.85
Email: [email protected]
visit us at http://www.systemworks.be
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]