Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / Hibernate не инициализируется / 4 сообщений из 4, страница 1 из 1
28.07.2007, 22:01:37
    #34690844
Новичёк Java
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Hibernate не инициализируется
Вот это:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
package hello;

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

import java.util.List;
import java.util.Iterator;

public class test {

    public test()
    {
        Configuration cfg=new Configuration();

        cfg.addResource("c:\\Event.hbm.xml");
    }
}

Выдает ошибку.

28.07.2007 20:49:48 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.4.sp1
28.07.2007 20:49:49 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
28.07.2007 20:49:49 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
28.07.2007 20:49:49 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
28.07.2007 20:49:49 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : c:\Event.hbm.xml
Exception in thread "main" org.hibernate.MappingNotFoundException: resource: c:\Event.hbm.xml not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:563)
at hello.test.<init>(test.java:17)
at hello.test.main(test.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)

Process finished with exit code 1


Файл Event.hbm.xml cуществует и путь правильный.

Что делать?
...
Рейтинг: 0 / 0
29.07.2007, 12:55:08
    #34691011
Новичёк Java
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Hibernate не инициализируется
Вроде победил. Шас новый глюк.

Вроде всё верно сделал. Как в документации.
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
package hello;

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

import java.util.List;
import java.util.Iterator;
import java.util.List;
import java.util.Iterator;
import java.util.Date;
import java.util.Locale;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import events.Event;

public class test {

    public test() throws Exception
    {

	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


        Configuration cfg=new Configuration();

        cfg.addResource("Event.hbm.xml");
        cfg.addResource("Person.hbm.xml");
        cfg.setProperty("hibernate.dialect","org.hibernate.dialect.Oracle9Dialect");
        cfg.setProperty("hibernate.connection.driver_class","oracle.jdbc.OracleDriver");
        cfg.setProperty("hibernate.connection.url","jdbc:oracle:thin:scott/tiger@//localhost:1521/orcl");
        cfg.setProperty("hibernate.show_sql","true");
        cfg.setProperty("hibernate.format_sql","true");
        cfg.setProperty("hibernate.use_sql_comments","true");


        //cfg.setProperties(System.getProperties());
	

        SessionFactory SessFact1 = cfg.buildSessionFactory();


		Session session1 = SessFact1.getCurrentSession();

		/*
		session.beginTransaction();

		        Event theEvent = new Event();
		        theEvent.setTitle("Title 1");
		        theEvent.setDdate(new Date());

	        session.save(theEvent);

	        session.getTransaction().commit();
		*/

		session1.close();


	SessFact1.close();
        
    }

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

        new test();
    }

}

29.07.2007 11:47:42 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
29.07.2007 11:47:42 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
29.07.2007 11:47:43 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured!
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:542)
at hello.test.<init>(test.java:64)
at hello.test.main(test.java:88)
...
Рейтинг: 0 / 0
29.07.2007, 13:16:26
    #34691028
Hibernate не инициализируется
где? ошибка? там же INFO
...
Рейтинг: 0 / 0
30.07.2007, 06:31:44
    #34691463
vas0
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Hibernate не инициализируется
ненавижу хибернейтгде? ошибка? там же INFO
там же написано
Новичёк JavaException in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured!

чтобы вызывать SessFact1.getCurrentSession(), CurrentSessionContext надо тоже конфигурить
Код: plaintext
       <property name="hibernate.current_session_context_class">thread</property>
а можно этого не делать и вызывать SessFact1.openSession();
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / Hibernate не инициализируется / 4 сообщений из 4, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]