|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
通过视频学习比传统的大课堂学习更适合成人化的学习规律。有人说大课堂气氛好,学习氛围浓,热闹,可以认识很多人。
hibernate4.3
利用hibernate4.3的时分猎取SessionFactory和之前纷歧样,网上看到一篇(StackOverFlow内里的),可使用上面的体例:- packageutil.hibernate;
- importorg.hibernate.HibernateException;
- importorg.hibernate.Session;
- importorg.hibernate.SessionFactory;
- importorg.hibernate.boot.registry.StandardServiceRegistry;
- importorg.hibernate.boot.registry.StandardServiceRegistryBuilder;
- importorg.hibernate.cfg.Configuration;
- publicclassHibernateUtil{
- privatestaticSessionFactoryfactory;
- static{
- try{
- Configurationconfiguration=newConfiguration().configure();
- StandardServiceRegistryserviceRegistry=newStandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
- factory=configuration.configure().buildSessionFactory(serviceRegistry);
- }catch(HibernateExceptione){
- e.printStackTrace();
- }
- }
- publicstaticSessionFactorygetSessionFactory(){
- returnfactory;
- }
- publicstaticSessiongetOpenSession(){
- returnfactory.openSession();
- }
- publicstaticSessiongetCurrentSession(){
- returnfactory.getCurrentSession();
- }
- publicstaticvoidcloseSession(Sessionsession){
- if(session!=null){
- if(session.isOpen()){
- session.close();
- }
- }
- }
- }
复制代码 利用StandardServiceRegister类来初始化我们的SessionFactory。
检察本栏目更多出色内容:http://www.bianceng.cn/Programming/Java/
可是在利用注解的时分,却呈现了上面的毛病:- java.lang.NoSuchMethodError:javax.persistence.Table.indexes()[Ljavax/persistence/Index;
- atorg.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:936)
- atorg.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:781)
- atorg.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3762)
- atorg.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3716)
- atorg.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410)
- atorg.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
- atutil.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:17)
- atHibernateTest.testSave(HibernateTest.java:24)
- atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
- atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
- atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- atjava.lang.reflect.Method.invoke(Method.java:606)
- atorg.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
- atorg.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
- atorg.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
- atorg.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
- atorg.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
- atorg.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
- atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
- atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
- atorg.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
- atorg.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
- atorg.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
- atorg.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
- atorg.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
- atorg.junit.runners.ParentRunner.run(ParentRunner.java:220)
- atorg.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
- atorg.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
- atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
- atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
- atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
- atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
复制代码 了局弄了很久都没弄定,可是我之前用4.3的是能够的,怎样回事?
经由过程对照,我发明在model类中假如利用了Table(name="t_user"),就会报如许的毛病,可是假如我写成@Entity(name="t_user")如许就没成绩了,这个多是Hibernate4.3的一个bug?这就不得而知了,不外假如用4.3的话,那末间接利用Entity来指定表名就能够办理这个成绩了。
自己的整个学习思路完全被老师的讲课思路所牵制,这样几节课听下来,恐怕自己的见解都应该是书里的知识点了,根本谈不上自身发现问题,分析问题,和解决问题能力的切实提高。 |
|