hibernate 中openSession()

Configuration cfg = new Configuration().configure();
SessionFactory factory = cfg.buildSessionFactory();
Session session = null;
session = factory.openSession();

上面代码中,factory不为空,但是session却为空?求解!谢谢!

2个回答

这个问题说明你前面的SessionFactory的获取就出了问题。建议你使用try..catch包围这两句话,看下获取SessionFactory对象过程中有没有出现异常。
此外检查下数据库连接的配置文件。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
hibernate4 openSession转换为getCurrentSession事务怎么处理?
# 项目中用openSession好使,不过领导要改成getCurrentSession,求教各位大神,配置文件事务处应该怎么改,求详解!!!急急急!!!
hibernate中sessionFactory问题
一对多映射 感觉没错,求解啊!!! ``` public class HibernateUtil { private static SessionFactory sessionFactory; private static Session session; static { //创建configuration对象,读取hibernate.cfg.xml文件,完成初始化 Configuration config = new Configuration().configure(); ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry(); sessionFactory = config.buildSessionFactory(serviceRegistry); //16 } //获取sessionFactory public static SessionFactory getSessionFactory() { return sessionFactory; } //获取session对象 public static Session getSession() { session = sessionFactory.openSession(); return session; } //关闭会话 public static void closeSession(Session session) { if(session!=null) { session.close(); } } } public class Test { public static void main(String[] args) { add(); //14 } //将学生添加到班级 public static void add() { Grade g = new Grade("java一班", "java软件开发一班"); Student s1 = new Student("张三", "男"); Student s2 = new Student("慕女神","女"); g.getStudents().add(s1); g.getStudents().add(s2); //保存班级、学生信息 Session session = HibernateUtil.getSession(); //29 Transaction transaction = session.beginTransaction(); session.save(g); session.save(s1); session.save(s2); transaction.commit(); HibernateUtil.closeSession(session); } } 错误信息: Exception in thread "main" java.lang.ExceptionInInitializerError at com.imooc.entity.Test.add(Test.java:29) at com.imooc.entity.Test.main(Test.java:14) Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185) at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:385) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1790) at com.imooc.util.HibernateUtil.<clinit>(HibernateUtil.java:16) ... 2 more Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer] at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:138) at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188) at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:341) at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:507) at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:146) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163) ... 6 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135) ... 15 more Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for student in class com.imooc.entity.Grade at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:316) at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:310) at org.hibernate.mapping.Property.getGetter(Property.java:321) at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:444) at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:200) at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:82) ... 20 more ```
hibernate中的事务问题
package cn.itcast.hibernatetest; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.junit.Test; import cn.itcast.entity.User; public class HibernateDemo { @Test public void testAdd() { //第一步 加载hibernate核心配置文件 //到src下面照到一个名词是hibernate.cfg.xml //在hibernate里面封装了一个对象 Configuration cfg=new Configuration(); cfg.configure(); //第二步,创建一个SessionFactory对象 //读取hibernate核心配置文件,创建sessionFactory //在过程中,根据映射关系,在配置数据库里面把表创建 SessionFactory sessionFactory = cfg.buildSessionFactory(); //第三步 使用SessionFactory创建session对象 //类似于连接 Session session = sessionFactory.openSession(); //第四步 开启事务 Transaction tx = session.beginTransaction(); //第五步 写具体逻辑crud操作 User user = new User(); user.setUsername("小王"); user.setPassword("250"); user.setAdress("日本"); //调用session的方法实现添加 session.save(user); //第六步 提交事务 tx.commit(); //第七步 关闭资源 session.close(); sessionFactory.close(); } } 代码tx.commit();报错,输入tx.的时候也没有提示commit()方法,为什么,错误提示好像是Transaction中没有commit方法? 错误提示如下: The type javax.persistence.EntityTransaction cannot be resolved. It is indirectly referenced from required .class files 有没有大神解答下,谢谢了
Hibernate Criteria 多表查询实体中有另一个实体 查询结果映射异常?
# Hibernate Criteria 多表查询 代码: 1. Affix类 ``` public class Affix { private int id; private String name; private String size; private Integer width; private Integer height; private Role role; ``` 2.Role 类 ``` public class Role { private int id; private String name; private String remark; ``` 3. mapping 配置 ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.cn.domain"> <class name="Affix" table="sys_affix" catalog="test"> <id name="id" column="id"> <generator class="native"></generator> </id> <property name="name" column="name" length="20"></property> <property name="size" column="size" length="50"></property> <property name="width" column="width" length="50" type="java.lang.Integer"></property> <property name="height" column="height" length="50" type="java.lang.Integer"></property> </class> <class name="Role" table="sys_role" catalog="test"> <id name="id" column="id"> <!-- 主键生成策略 --> <generator class="native"></generator> </id> <property name="name" column="name" length="20"></property> <property name="remark" column="remark" length="50"></property> </class> </hibernate-mapping> ``` 4.Dao层 ``` public class AffixDao { public List selectAffix(){ Session session = HibernateUtils.openSession(); session.beginTransaction(); Criteria criteria = session.createCriteria(Affix.class);//1.总的查询容器 criteria.createAlias("role","r"); criteria.add(Restrictions.eq("r.id", 1)); List list = criteria.list(); List<Affix> lists = list; System.out.println("查询结果条数:"+list.size()); session.close(); return list; } } ``` 5.执行结果 org.hibernate.QueryException: could not resolve property: role of: com.cn.domain.Affix at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:62) at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:56) at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1753) at org.hibernate.loader.criteria.EntityCriteriaInfoProvider.getType(EntityCriteriaInfoProvider.java:39) at org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathInfo(CriteriaQueryTranslator.java:228) at org.hibernate.loader.criteria.CriteriaQueryTranslator.createCriteriaEntityNameMap(CriteriaQueryTranslator.java:212) at org.hibernate.loader.criteria.CriteriaQueryTranslator.<init>(CriteriaQueryTranslator.java:94) at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:71) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1760) at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363) at com.cn.dao.AffixDao.selectAffix(AffixDao.java:45) at com.cn.dao.AffixDaoTest.testSelectAffix(AffixDaoTest.java:16) 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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) # 问题: 网上搜过好多类似的实例代码,别人都可以执行成功,我这里一直报role在Affix中映射异常,有没有大神可以指点一下?谢谢
hibernate中 load延迟加载失效
代码运行没有问题 但是延迟加载没有效果![图片说明](https://img-ask.csdn.net/upload/201803/17/1521299031_723795.png) 图片中是debug效果 输出c 这个语句还没有执行就已经打印了sql语句这个结果和get方法结果一模一样 延迟加载应该是使用时才打印sql语句然后和结果一起输出 求大神指点 <hibernate-mapping package="cn.itcast.domain" > <class name="Customer" table="cst_customer" lazy="true" > <id name="cust_id" > <generator class="increment"></generator> </id> <property name="cust_name" column="cust_name" ></property> <property name="cust_source" column="cust_source" ></property> <property name="cust_industry" column="cust_industry" ></property> <property name="cust_level" column="cust_level" ></property> <property name="cust_linkman" column="cust_linkman" ></property> <property name="cust_phone" column="cust_phone" ></property> <property name="cust_mobile" column="cust_mobile" ></property> </class> </hibernate-mapping> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql:///hibernate32</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.format_sql">true</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.connection.isolation">4</property> <property name="hibernate.current_session_context_class">thread</property> <mapping resource="cn/itcast/domain/Customer.hbm.xml" /> </session-factory> </hibernate-configuration> @Test public void fun2(){ Session session = HibernateUtils.openSession(); Transaction tx = session.beginTransaction(); //---------------------------------------------------- Customer c = session.load(Customer.class, 2l); System.out.println(c); //---------------------------------------------------- tx.commit(); session.close(); }
Springboot集成hibernate+HibernateDaoSupport
``` package com.ruoyi.project.common.base.dao; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import org.hibernate.Query; import org.hibernate.SQLQuery; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.transform.Transformers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.repository.Modifying; import org.springframework.orm.hibernate5.support.HibernateDaoSupport; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import com.ruoyi.common.dto.BaseDtoImpl; import com.ruoyi.common.dto.IBaseDto; import com.ruoyi.common.utils.SystemExtUtils; import com.ruoyi.common.utils.json.Json; @Transactional @Repository("baseDao") public class BaseDaoImpl extends HibernateDaoSupport implements IBaseDao { @Autowired public void setSuperSessionFactory(SessionFactory sessionFactory) { super.setSessionFactory(sessionFactory); } // @Autowired // private EntityManagerFactory entityManagerFactory; // public Session getSession() { // return entityManagerFactory.unwrap(SessionFactory.class).openSession(); // } @Override public <T> void saveOrUpdateNow(T clazz){ Session session=this.getSession(); session.merge(clazz); //立即写入数据库并释放内存 session.flush(); session.clear(); } @Override @Transactional public <T> void saveOrUpdate(T clazz){ Session session=this.getSession(); //方法三 session.beginTransaction(); session.saveOrUpdate(clazz); Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.hibernate.SessionFactory' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} ``` ![图片说明](https://img-ask.csdn.net/upload/201910/05/1570286693_807259.png) Maven工程,是网上若依的,但是我们这边用是Hibernate,所以想改成Hibernate的,但是真心问题多 我们还Hibernate这里继承HibernateDaoSupport来实现,出现如上错误 不写方法 @Autowired public void setSuperSessionFactory(SessionFactory sessionFactory) { super.setSessionFactory(sessionFactory); } 的时候错误出下 Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required 用Hibernate的人少了,人熟悉这块的吗
struts2 spring hibernate整合后报错
在eclipse里面run on server之后,可以正确显示界面,但当填写表单点击按钮后出现了这个报错 Struts Problem Report Struts has detected an unhandled exception: Messages: 1.org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session; 2.Method "execute" failed for object com.action.LoginAction@5582c63b File: org/springframework/orm/hibernate3/SessionFactoryUtils.java Line number: 328 Stacktraces ognl.MethodFailedException: Method "execute" failed for object com.action.LoginAction@5582c63b [java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;] ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1305) ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68) com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor ...... 这个是什么问题啊??
hibernate中qurey查询 用Junit测试报错
我的工具 myeclipse 8.5 +oracle 10g 1.实体类映射文件Student.hbm.xml [code="java"]<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.softeem.pojo"> <class name="Student" table="tb_student"> <id name="sno"> <generator class="native"></generator> </id> <property name="sname"/> <property name="ssex"/> <property name="sage"/> <property name="stime"/> </class> </hibernate-mapping>[/code] 2.hibernate配置文件hibernate.cfg.xml [code="java"]<!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="show_sql">true</property> <property name="dialect"> org.hibernate.dialect.Oracle9Dialect </property> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </property> <property name="connection.url"> jdbc:oracle:thin:@localhost:1521:softeem </property> <property name="connection.username">java1103</property> <property name="connection.password">java1103</property> <mapping resource="com/softeem/pojo/Student.hbm.xml" /> </session-factory> </hibernate-configuration>[/code] 3.test测试类CURDTest.java [code="java"]package com.softeem.test; import java.util.Date; import java.util.Iterator; import java.util.List; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import com.softeem.pojo.Student; import junit.framework.TestCase; public class CURDTest extends TestCase{ //增 public void insertTest(){ Configuration config=new Configuration().configure(); SessionFactory sf=config.buildSessionFactory(); Session session=sf.openSession(); session.beginTransaction(); //增加十条记录 for(int i=0;i<10;i++){ Student stu=new Student(); stu.setSname("顾超"); stu.setSsex("男"); stu.setSage(21); stu.setStime(new Date()); session.save(stu); } session.getTransaction().commit(); session.close(); } //删 public void deleteTest(){ Configuration config=new Configuration().configure(); SessionFactory sf=config.buildSessionFactory(); Session session=sf.openSession(); session.beginTransaction(); Student stu=(Student) session.load(Student.class, 1); session.delete(stu); session.getTransaction().commit(); session.close(); } //改 public void updateTest(){ Configuration config=new Configuration().configure(); SessionFactory sf=config.buildSessionFactory(); Session session=sf.openSession(); session.beginTransaction(); Student stu=(Student) session.load(Student.class, 2); stu.setSname("小强"); stu.setSage(1); session.update(stu); session.getTransaction().commit(); session.close(); } //查 public void selectTest(){ Configuration config=new Configuration().configure(); SessionFactory sf=config.buildSessionFactory(); Session session=sf.openSession(); session.beginTransaction(); Student stu=(Student) session.load(Student.class,2); System.out.println(stu.getSno()+" "+stu.getSname()+" "+stu.getSsex()+" "+stu.getSage()+" "+stu.getStime()); //Query query=new Query("from tb_student"); session.getTransaction().commit(); session.close(); } // //查找全部 // public void selectAllTest(){ // Configuration config=new Configuration().configure(); // SessionFactory sf=config.buildSessionFactory(); // Session session=sf.openSession(); // session.beginTransaction(); // Query query=session.createQuery("from tb_student"); // List<?> list=query.list(); // Iterator<?> it=list.iterator(); // while(it.hasNext()){ // Student stu=(Student) it.next(); // System.out.println(stu.getSno()+" "+stu.getSname()+" "+stu.getSsex()+" "+stu.getSage()+" "+stu.getStime()); // } // session.getTransaction().commit(); // session.close(); // } // // //分页 // public void pagingTest(){ // Configuration config=new Configuration().configure(); // SessionFactory sf=config.buildSessionFactory(); // Session session=sf.openSession(); // session.beginTransaction(); // Query query=session.createQuery("form tb_student"); // query.setFirstResult(3); // query.setMaxResults(3); // List<?> list=query.list(); // for(int i=0;i<list.size();i++){ // System.out.println(list.get(i)); // } // session.getTransaction().commit(); // session.close(); // } // // //模糊查询 // public void blurTest(){ // Configuration config=new Configuration().configure(); // SessionFactory sf=config.buildSessionFactory(); // Session session=sf.openSession(); // session.beginTransaction(); // Query query=session.createQuery("form tb_student where sname like ?"); // query.setString(0, "%小%"); // List<?> list=query.list(); // for(int i=0;i<list.size();i++){ // System.out.println(list.get(i)); // } // session.getTransaction().commit(); // session.close(); // } } [/code] 问题是: [code="java"]Query query=session.createQuery("from tb_student");[/code]这条语句会报错 当我改成: [code="java"]Query query=session.createSQLQuery("select * from tb_student");[/code]这条语句不会报错,但是 [code="java"]Student stu=(Student) it.next(); [/code]这条语句就会报错. 不知道什么原因,纠结了很久。请大家指点。
在eclipse中运行Hibernate,出现Autocommit mode: false错误
我的Hibernate版本是:5.2.2以下是代码与错误提示 no1 一月 13, 2017 9:25:47 下午 org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {5.2.2.Final} 一月 13, 2017 9:25:47 下午 org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found 一月 13, 2017 9:25:47 下午 org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist no2 一月 13, 2017 9:25:47 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final} 一月 13, 2017 9:25:47 下午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time. 一月 13, 2017 9:25:48 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!) 一月 13, 2017 9:25:48 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql:///testhibernate] 一月 13, 2017 9:25:48 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH10001001: Connection properties: {user=root, password=****} 一月 13, 2017 9:25:48 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH10001003: Autocommit mode: false Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:36) at org.hibernate.engine.jdbc.connections.internal.PooledConnections.<init>(PooledConnections.java:20) at org.hibernate.engine.jdbc.connections.internal.PooledConnections$Builder.build(PooledConnections.java:161) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:109) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:72) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:257) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87) at org.hibernate.boot.MetadataSources.buildMetadata(MetadataSources.java:179) at com.hibernate.test1.test.main(test.java:17) --------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql:///testhibernate</property> <property name="connection.username">root</property> <property name="connection.password">root</property> <!-- <property name="dialect">org.hibernate.dialect.MySQLDialect</property> --> <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> <property name="hbm2ddl.auto">update</property> <property name="show_sql">true</property> <mapping resource="com/hibernate/bean/LoginBean.hbm.xml"/> </session-factory> </hibernate-configuration> ----------------------------------------------------------- package com.hibernate.test1; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; public class test { public static void main(String[] args) { // TODO Auto-generated method stub StandardServiceRegistry registry=new StandardServiceRegistryBuilder().configure().build(); SessionFactory sessionfactory=new MetadataSources(registry).buildMetadata().buildSessionFactory(); Session session=sessionfactory.openSession(); Transaction transaction=session.beginTransaction(); log log1=new log(); log1.setName("nihao"); log1.setPass("dkjk"); session.save(log1); transaction.commit(); } } ----------------------------------------------- <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 2017-1-13 18:13:48 by Hibernate Tools 3.5.0.Final --> <hibernate-mapping> <class name="com.hibernate.test.log" table="LOG"> <id name="name" type="java.lang.String"> <column name="NAME" /> <generator class="assigned" /> </id> <property name="pass" type="java.lang.String"> <column name="PASS" /> </property> </class> </hibernate-mapping>
如何使Hibernate中EhCache缓存的Key能够动态设置
您好! 我现在在Hibernate中用EhCache做缓存,hibernate在对对象操作时自动缓存数据,但是缓存的key为对象的主键,我现在想对这个key在缓存前加上一个标识,因为我想对hibernate进行多schema扩展,所以如果用hibernate自己的缓存策略,相同的对象在schema切换后可能主键相同,那么缓存就会出现问题。求大牛帮忙下。谢谢! 伪代码描述如下: //前提,Schema1中已经缓存了主键为1的用户信息。 Session session = null; User user = null; //1、这里用Schema1创建Session,通过缓存获取主键为1的用户 session = Schema1.sessionFactory.openSession(); user = session.get(1); session.close(); //2、这里用Schema2创建Session,通过缓存获取主键为1的用户,但是 //拿出来的用户信息却是Schema1中的主键为1的用户信息,所以我想 //在hibernate进行二级缓存时,对缓存key进行操作,添加标识。 session = Schema2.sessionFactory.openSession(); user = session.get(1); session.close();
hibernate 中的load方法出现异常 不想关闭懒加载还有什么方法可以解决这个异常
// 1.创建一个SessionFactory对象 SessionFactory sessionFactory = null; // 2.创建session对象 Session session = null; @Before public void init() { // 3.把注册信息传入ServiceRegistry接口中 Hibernate5.X做法 StandardServiceRegistry registry = new StandardServiceRegistryBuilder() .configure().build(); try { // 4.获取sessionFactory sessionFactory = new MetadataSources(registry).buildMetadata() .buildSessionFactory(); } catch (Exception e) { // 出现异常需要销毁StandardServiceRegistry注册表 StandardServiceRegistryBuilder.destroy(registry); } // 5.获取session对象 session = sessionFactory.openSession(); // 6.开启事务 session.beginTransaction(); } @Test public void testGet() { // 加载 使用get User u =session.get(User.class,1); System.out.println(u.getClass()); } @Test public void testLoad() { User u =session.load(User.class,2); System.out.println(u.getClass()); } @After public void close() { // 8.提交事务 session.getTransaction().commit(); // 9.释放所有资源 session.close(); sessionFactory.close(); } 控制台是: java.lang.ClassCastException: com.ltt.user.User_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy 2018-5-24 20:05:25 org.hibernate.event.internal.DefaultLoadEventListener doOnLoad INFO: HHH000327: Error performing load command : org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: com.ltt.user.User 2018-5-24 20:05:25 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop INFO: HHH10001008: Cleaning up connection pool [jdbc:mysql:///test0221] Junit界面是:org.hibernate.HibernateException: HHH000142: Javassist Enhancement failed: com.ltt.user.User 我就是想问如果不在映射文件中设置class标签中的lazy属性为false怎么才能消除异常 设置为lazy=false之后那load和get方法不是一样了吗?都变成了立即搜索
hibernate执行保存对象时出现异常:org.hibernate.exception.GenericJDBCException
hibernate执行保存对象时出现异常: org.hibernate.exception.GenericJDBCException: could not insert: [com.hibernate.domain.User] Caused by: java.sql.SQLException: Field 'user_id' doesn't have a default value 具体的代码和配置如下: **hibernate.cfg.xml:** <hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/hibernate3</property> <property name="connection.username">root</property> <property name="connection.password">ytkj</property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.MySQLDialect</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 --> <!-- show sql dml --> <property name="show_sql">true</property> <!-- Drop and re-create the database schema on startup --> <!-- <property name="hbm2ddl.auto">update</property> --> <mapping resource="com/hibernate/domain/User.hbm.xml"/> </session-factory> </hibernate-configuration> ------------------------------------------------------------------------ 建表语句(成功): CREATE TABLE `t_user` ( `user_id` int(11) NOT NULL, `user_name` varchar(20) default NULL, `user_age` int(11) default NULL, PRIMARY KEY (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ------------------------------------------------------------------ **测试类:** package com.hibernate.manager; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import com.hibernate.domain.User; import com.hibernate.util.HibernateUtil; public class UserManager { public static void main(String[] args) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); Transaction ts = session.beginTransaction(); User user = new User(); user.setId(1); user.setName("zhangsan"); user.setAge(21); session.save(user); ts.commit(); session.close(); sessionFactory.close(); } } ----------------------------------------------------------------------- **User.hbm.xml:** <hibernate-mapping package="com.hibernate.domain"> <class name="User" table="t_user"> <id name="id" column="user_id"> <generator class="native"/> </id> <!-- <id name="id" type="int" column="user_id"/> --> <property name="name" type="string" column="user_name"/> <property name="age" type="int" column="user_age"/> </class> </hibernate-mapping> ------------------------------------------------------------------------- 以上代码执行过后,就包上面的异常。 如果不使用id生成策略(及时没有generator标签),则可以insert成功。 请问这问题是出在哪里?高手指点。
hibernate事务开启不成功的错误
package cn.jbit.test; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; import cn.jbit.entity.User; import cn.jbit.util.HibernateUtil; public class test { private static final SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); public static void main(String[] args) { Session session=null; Transaction tx=null; try { Configuration cfg=new Configuration().configure(); ServiceRegistry serviceRegistry=new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry(); SessionFactory sessionFactory=cfg.buildSessionFactory(serviceRegistry); session=sessionFactory.openSession(); tx=session.beginTransaction(); User user=new User(); user.setName("liufang"); user.setBorn(sdf.parse("1990-08-06")); session.save(user); tx.commit(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch (Exception e) { // TODO: handle exception if(session!=null){ session.getTransaction().rollback(); } }finally{ HibernateUtil.closeSession(session); } } } 报错信息: log4j:WARN No appenders could be found for logger (org.jboss.logging). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Exception in thread "main" org.hibernate.TransactionException: Transaction not successfully started at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:200) at cn.jbit.test.test.main(test.java:43) 相应jar包如图所示: ![图片说明](https://img-ask.csdn.net/upload/201503/30/1427703883_43525.png) hibernate.xml <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <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/test</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> <property name="show_sql">true</property> <!--<property name="hibernate.hbm2ddl.auto">update</property> --><mapping resource="cn/jbit/entity/User.hbm.xml"/> </session-factory> </hibernate-configuration> User.hbm.xml配置文件 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <!-- Demonstrates use of the enhanced sequence-based identifier generator, with no performance optimizations (the DB is hit everytime when generating a value). --> <hibernate-mapping package="cn.jbit.entity"> <class name="User" table="t_user"> <id name="id" column="id"> <generator class="native"><!-- <param name="table_name">ID_SEQ_TBL_BSC_SEQ</param> --></generator> </id> <property name="name" type="string"/> <property name="born" type="timestamp"/> </class> </hibernate-mapping>
hibernate5.2.4:每次运行hibernate都会创建表
我导入的jar包是required里所有和jdbc hibernate.cfg.xml 注意hbm2ddl.auto属性 ``` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="hibernate.connection.password">scott</property> <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:orcl</property> <property name="hibernate.connection.username">scott</property> <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.format_sql">true</property> <property name="hibernate.hbm2ddl.auto">update</property> <mapping resource="entity/Emp.hbm.xml"/> <mapping resource="entity/Dept.hbm.xml"/> </session-factory> </hibernate-configuration> ``` emp映射文件 ``` <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="entity.Emp" table="EMP"> <id name="empno" type="java.lang.Integer"/> <property name="ename" type="java.lang.String"/> <property name="job" type="java.lang.String"/> <property name="mgr" type="java.lang.Integer"/> <property name="hiredate" type="java.sql.Date"/> <property name="sal" type="java.lang.Double"/> <property name="comm" type="java.lang.Double"/> <many-to-one class="entity.Dept" column="deptno" name="d"/> </class> </hibernate-mapping> ``` dept映射文件 ``` <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="entity.Dept" table="DEPT"> <id name="deptno" type="java.lang.Integer"/> <property generated="never" lazy="false" name="dname" type="java.lang.String"/> <property generated="never" lazy="false" name="loc" type="java.lang.String"/> <list name="l" table="EMP"> <key column="deptno"/> <list-index column="deptNo"/> <one-to-many class="entity.Emp"/> </list> </class> </hibernate-mapping> ``` java测试类 ``` package test; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import entity.Emp; public class Test { public static void main(String[] args) { StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure().build(); SessionFactory sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); Session session = sessionFactory.openSession(); session.beginTransaction(); Emp e = new Emp(); e.setEmpno(652); session.save(e); session.getTransaction().commit(); } } ``` 控制台信息 ``` 十一月 21, 2016 8:56:30 下午 org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {5.2.4.Final} 十一月 21, 2016 8:56:30 下午 org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found 十一月 21, 2016 8:56:30 下午 org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist 十一月 21, 2016 8:56:31 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final} 十一月 21, 2016 8:56:31 下午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time. 十一月 21, 2016 8:56:32 下午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-mapping. Use namespace http://www.hibernate.org/dtd/hibernate-mapping instead. Support for obsolete DTD/XSD namespaces may be removed at any time. 十一月 21, 2016 8:56:32 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!) 十一月 21, 2016 8:56:32 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH10001005: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thava:191) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523) at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:193) at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:999) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1315) at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1890) at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1855) at oracle.jdbc.driver.OracleStatementWrapper.execute(OracleStatementWrapper.java:304) at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ``` 如果我把hbm2ddl属性换成create也会造成这种冲突,请问大神怎么破
hibernate 异常求解决
11:07:37,716 INFO Version:37 - Hibernate Commons Annotations 3.2.0.Final 11:07:37,723 INFO Environment:603 - Hibernate 3.6.10.Final 11:07:37,724 INFO Environment:636 - hibernate.properties not found 11:07:37,727 INFO Environment:814 - Bytecode provider name : javassist 11:07:37,729 INFO Environment:695 - using JDK 1.4 java.sql.Timestamp handling 11:07:37,771 INFO Configuration:2156 - configuring from resource: /hibernate.cfg.xml 11:07:37,771 INFO Configuration:2175 - Configuration resource: /hibernate.cfg.xml 11:07:37,826 INFO Configuration:789 - Reading mappings from resource : cn/wyz/domain/Customer.hbm.xml 11:07:37,891 INFO Configuration:2297 - Configured SessionFactory: null 11:07:37,923 INFO HbmBinder:353 - Mapping class: cn.wyz.domain.Customer -> customer 11:07:37,936 INFO Configuration:1676 - Hibernate Validator not found: ignoring 11:07:37,940 INFO HibernateSearchEventListenerRegister:75 - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled. Customer.hbm.xml文件 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="cn.wyz.domain.Customer" table="customer" catalog="customer"> <id name="id" column="id" type="int"> <generator class="native"></generator> </id> <property name="name" column="name" type="java.long.String"></property> <property name="age" column="age" type="int"></property> <property name="city" column="city" type="java.long.String"></property> </class> </hibernate-mapping> hibernate.cfg.xml文件 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql:///customer</property> <property name="hibernate.connection.username">wyz</property> <property name="hibernate.connection.password">123456</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.format_sql">true</property> <property name="hibernate.hbm2ddl.auto">update</property> <mapping resource="cn/wyz/domain/Customer.hbm.xml"/> </session-factory> </hibernate-configuration> 测试类 public class HibernateTest1 { @Test public void testAdd() { // 实例化配置对象,加载配置文件 hibernate.cfg.xml Configuration configuration = new Configuration().configure(); // 创建会话连接工厂 SessionFactory sessionFactory = configuration.buildSessionFactory(); // 创建会话 Session session = sessionFactory.openSession(); // 开启事务 Transaction transaction = session.beginTransaction(); // 这里可以编写hibernate操作代码逻辑 Customer customer=new Customer(); customer.setName("张三"); customer.setAge(18); customer.setCity("河北"); session.save(customer); // 提交事务,释放资源 transaction.commit(); session.close(); sessionFactory.close(); } }
Hibernate中的获得session问题
Session session = HbernateSession.currentSession(),这样获取session就可以不需要读配置文件了吗? 跟以下写法是一样的吗? Configureation conf = new Configureation().configure(); //这是加载默认的hibernate.hbm.xml配置 文件SessionFactory sessions = new buildSessionFactory();Session session = sessions.openSession()
hibernate ThreadLocal
1.在hibernate的工具类中获取session的时候采用的是ThreadLocal方式,因为session是线程不安全的,可是如果我们用的是strut2或者struts1,这种不是线程的框架,不就没问题了吗? 2。openSession和getCurrentSession中提到getCurrentSession是把session绑定到当前的线程具体是什么意思啊。 3,总之,大家可以告诉我如果不用threadLocal会出现什么情况,详细点,现在糊涂了。始终不明白。 4。如果采用配置在配置文件加入thread是不是就不用使用threadLocal在工具类里面了 hibernate新手,求指教谢谢,希望详细点,谢谢
一个hibernate连接oracle11g的问题
<?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="connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="connection.url">jdbc:oracle:thin:@localhost:1521:ORCL</property> <property name="connection.username">scott</property> <property name="connection.password">tiger</property> <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property> <!-- Database config setting --> <!--<property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property> <property name="connection.username">root</property> <property name="connection.password">123</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property>--> <!-- JDBC connection pool (use the built-in) --> <!--<property name="connection.pool_size">1</property>--> <!-- SQL dialect --> <!--<property name="dialect">org.hibernate.dialect.MySQLDialect</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> <property name="format_sql">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">create</property> <!-- 使用xml配置方法的需要对下面的resource进行配置--> <mapping resource="com/sjy/hibernate/model/Student.hbm.xml"/> <mapping class="com.sjy.hibernate.model.Teacher"/> <!-- 使用annotation的需要对下面的class进行配置--> <!--<mapping class="org.hibernate.tutorial.domain.Event.hbm.xml" />--> </session-factory> </hibernate-configuration> 这个是我的hibernate配置文件 -------------------------------- <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.sjy.hibernate.model"> <class name="Student" table="student"> <id name="id"> <generator class="native"></generator> </id> <property name="name"></property> <property name="age"></property> </class> </hibernate-mapping> 这个是类的配置文件 ------------------------------ package com.sjy.hibernate.model; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; public class StudentTest { private static SessionFactory sf; @BeforeClass public static void beforeClass(){ Configuration cfg = new Configuration(); cfg.configure(); ServiceRegistry sr = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry(); sf = cfg.buildSessionFactory(sr); } @Test public void studentTest(){ Student s = new Student(); s.setAge(2); s.setName("hello"); Session session = sf.openSession(); session.beginTransaction(); session.save(s); session.getTransaction().commit(); session.close(); } @AfterClass public static void afterClass(){ sf.close(); } } 这个是我的测试代码 -------------- package com.sjy.hibernate.model; public class Student { private int id; private String name; private int age; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } 这个是student这个类 ------------------------- 我出的问题是连接oracle11g的时候老出空指针错误而且它里面报的是sf = cfg.buildSessionFactory(sr);sf 的空指针错误求告说解答下这个是什么错误啊 我这个配置换成mysql是好的能建表和插入数据但是换成oracle就成了空指针错误还有我的oracle里面导入的是classes12.jar 和ojdbc1.4jar这个两个包但是我认为不是导入jar包的问题
求大神解答 hibernate Multi-tenancy多租户connection空指针?
hibernate Multi-tenancy多租户为什么connection总是空指针? ``` 运行错误详情 Exception in thread "main" java.lang.NullPointerException at org.hibernate.c3p0.internal.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:73) at com.qzd.hibernate.MultiTenantConnectionProviderImpl.getAnyConnection(MultiTenantConnectionProviderImpl.java:65) at com.qzd.hibernate.MultiTenantConnectionProviderImpl.getConnection(MultiTenantConnectionProviderImpl.java:78) at org.hibernate.internal.AbstractSessionImpl$ContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:429) at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:84) at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:109) at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getConnectionForTransactionManagement(LogicalConnectionManagedImpl.java:227) at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.begin(LogicalConnectionManagedImpl.java:234) at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.begin(JdbcResourceLocalTransactionCoordinatorImpl.java:214) at org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:52) at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1525) at com.qzd.hibernate.TestMultiTenancy.main(TestMultiTenancy.java:40) ``` ``` hibernate.cfg.xml配置 <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.cache.use_query_cache">true</property> <property name="hibernate.cache.use_second_level_cache">true</property> <property name="hibernate.cache.use_structured_entries">true</property> <property name="hibernate.cache.region.factory_class">org.hibernate.cache.EhCacheRegionFactory</property> <property name="net.sf.ehcache.configurationResourceName">ehcache.xml</property> <property name="hibernate.connection.provider_class"> org.hibernate.c3p0.internal.C3P0ConnectionProvider </property> <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/hibernate </property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password"> ,an.123;kun </property> <property name="hibernate.c3p0.min_size">3</property> <property name="hibernate.c3p0.max_size">10</property> <property name="hibernate.c3p0.timeout">1500</property> <property name="hibernate.dialect"> org.hibernate.dialect.MySQL5Dialect </property> <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="myeclipse.connection.profile">mysql</property> <property name="connection.url"> jdbc:mysql://localhost:3306/hibernate </property> <property name="connection.username">root</property> <property name="connection.password">,an.123;kun</property> <property name="connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="hibernate.multiTenancy">shema</property> <property name="hibernate.multi_tenant_connection_provider">com.qzd.hibernate.MultiTenantConnectionProviderImpl</property> <mapping resource="com/qzd/hibernate/People.hbm.xml" /> <mapping resource="com/qzd/hibernate/Wife.hbm.xml" /> <mapping resource="com/qzd/hibernate/Child.hbm.xml" /> <mapping resource="com/qzd/hibernate/Address.hbm.xml" /> <mapping resource="com/qzd/hibernate/Person.hbm.xml" /> <mapping resource="com/qzd/hibernate/Tempbook.hbm.xml" /> <mapping resource="com/qzd/hibernate/Tempkind.hbm.xml" /> </session-factory> </hibernate-configuration> ``` ``` package com.qzd.hibernate; import java.sql.Connection; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import java.util.Properties; import javax.sql.DataSource; import org.apache.commons.dbcp2.BasicDataSource; import org.hibernate.HibernateException; import org.hibernate.c3p0.internal.C3P0ConnectionProvider; import org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl; import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider; import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.ServiceRegistryAwareService; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.Stoppable; import org.springframework.jdbc.datasource.DriverManagerDataSource; public class MultiTenantConnectionProviderImpl implements MultiTenantConnectionProvider,Configurable,Stoppable,ServiceRegistryAwareService{ private C3P0ConnectionProvider connectionProvider=new C3P0ConnectionProvider(); @Override public boolean isUnwrappableAs(Class arg0) { // TODO Auto-generated method stub return false; } @Override public <T> T unwrap(Class<T> arg0) { // TODO Auto-generated method stub return null; } @Override public void stop() { // TODO Auto-generated method stub } @Override public Connection getAnyConnection() throws SQLException { Connection conn = null; try { conn = connectionProvider.getConnection(); } catch (SQLException e) { throw new SQLException(e); } finally { System.out.println("222222222222222222888888888::" + (conn == null)); } return connectionProvider.getConnection(); } @Override public Connection getConnection(String tenantIdentifier) throws SQLException { final Connection connection = getAnyConnection(); try { connection.createStatement().execute( "USE " + tenantIdentifier ); } catch ( SQLException exception ) { throw new HibernateException( "Could not alter JDBC connection to specified schema [" +tenantIdentifier + "]", exception ); } return connection; } @Override public void releaseAnyConnection(Connection connection) throws SQLException { connectionProvider.closeConnection(connection); } @Override public void releaseConnection(String tenantIdentifier, Connection connection)throws SQLException { try { connection.createStatement().execute( "USE antest" ); } catch ( SQLException exception) { throw new HibernateException( "Could not alter JDBC connection to specified schema [" + tenantIdentifier + "]", exception ); } connectionProvider.closeConnection( connection ); } @Override public boolean supportsAggressiveRelease() { // TODO Auto-generated method stub return false; } @Override public void configure(Map props) { Properties c3props = new Properties(); Map allProps = new HashMap(); allProps.putAll( props ); allProps.putAll( c3props ); } @Override public void injectServices(ServiceRegistryImplementor arg0) { // TODO Auto-generated method stub } } ``` ``` 测试文件代码 package com.qzd.hibernate; import java.util.HashMap; import java.util.List; import java.util.Map; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl; import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReaderFactory; import org.hibernate.envers.query.AuditEntity; import org.hibernate.envers.query.AuditQuery; import com.qzd.shop.web.bean.Book; public class TestMultiTenancy { public static void main(String args[]) { Configuration config = new Configuration(); StandardServiceRegistryBuilder standardRegistryBuilder = new StandardServiceRegistryBuilder(); standardRegistryBuilder.configure("hibernate.cfg.xml").applySetting( "hibernate.multiTenancy", org.hibernate.MultiTenancyStrategy.SCHEMA); StandardServiceRegistry standardRegistry = standardRegistryBuilder .build(); SessionFactory sessionFactory = config .buildSessionFactory(standardRegistry); Session session = sessionFactory.withOptions() .tenantIdentifier("hibernate").openSession(); Transaction trans = session.beginTransaction(); try { Query query=session.createQuery("select new list(book.bookName,book.author,book.price) from Book book where book.bookId=3"); query.list().forEach((c)->System.out.println(c)); trans.commit(); } catch (Exception ex) { try { trans.rollback(); } catch (HibernateException e) { System.out.print(e.getMessage()); } System.out.println(ex.getMessage()); } finally { session.close(); sessionFactory.close(); } } } ``` 求大神解答,不胜感激。
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
JSON解析——net.sf.json.JSONObject
简介 在程序开发过程中,在参数传递,函数返回值等方面,越来越多的使用JSON。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,同时也易于机器解析和生成、易于理解、阅读和撰写,而且Json采用完全独立于语言的文本格式,这使得Json成为理想的数据交换语言。 JSON建构于两种结构: “名称/值”对的集合(A Collection of name/va...
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我...
2019年还剩1天,我从外包公司离职了
这日子过的可真快啊,2019年还剩1天,外包公司干了不到3个月,我离职了
我一个37岁的程序员朋友
周末了,人一旦没有点事情干,心里就瞎想,而且跟几个老男人坐在一起,更容易瞎想,我自己现在也是 30 岁了,也是无时无刻在担心自己的职业生涯,担心丢掉工作没有收入,担心身体机能下降,担心突...
计算机网络的核心概念
这是《计算机网络》系列文章的第二篇文章 我们第一篇文章讲述了计算机网络的基本概念,互联网的基本名词,什么是协议以及几种接入网以及网络传输的物理媒体,那么本篇文章我们来探讨一下网络核心、交换网络、时延、丢包、吞吐量以及计算机网络的协议层次和网络攻击。 网络核心 网络的核心是由因特网端系统和链路构成的网状网络,下面这幅图正确的表达了这一点 那么在不同的 ISP 和本地以及家庭网络是如何交换信息的呢?...
python自动下载图片
近日闲来无事,总有一种无形的力量萦绕在朕身边,让朕精神涣散,昏昏欲睡。 可是,像朕这么有职业操守的社畜怎么能在上班期间睡瞌睡呢,我不禁陷入了沉思。。。。 突然旁边的IOS同事问:‘嘿,兄弟,我发现一个网站的图片很有意思啊,能不能帮我保存下来提升我的开发灵感?’ 作为一个坚强的社畜怎么能说自己不行呢,当时朕就不假思索的答应:‘oh, It’s simple. Wait for me a few
一名大专同学的四个问题
【前言】   收到一封来信,赶上各种事情拖了几日,利用今天要放下工作的时机,做个回复。   2020年到了,就以这一封信,作为开年标志吧。 【正文】   您好,我是一名现在有很多困惑的大二学生。有一些问题想要向您请教。   先说一下我的基本情况,高考失利,不想复读,来到广州一所大专读计算机应用技术专业。学校是偏艺术类的,计算机专业没有实验室更不用说工作室了。而且学校的学风也不好。但我很想在计算机领...
复习一周,京东+百度一面,不小心都拿了Offer
京东和百度一面都问了啥,面试官百般刁难,可惜我全会。
Java 14 都快来了,为什么还有这么多人固守Java 8?
从Java 9开始,Java版本的发布就让人眼花缭乱了。每隔6个月,都会冒出一个新版本出来,Java 10 , Java 11, Java 12, Java 13, 到2020年3月份,...
达摩院十大科技趋势发布:2020 非同小可!
【CSDN编者按】1月2日,阿里巴巴发布《达摩院2020十大科技趋势》,十大科技趋势分别是:人工智能从感知智能向认知智能演进;计算存储一体化突破AI算力瓶颈;工业互联网的超融合;机器间大规模协作成为可能;模块化降低芯片设计门槛;规模化生产级区块链应用将走入大众;量子计算进入攻坚期;新材料推动半导体器件革新;保护数据隐私的AI技术将加速落地;云成为IT技术创新的中心 。 新的画卷,正在徐徐展开。...
轻松搭建基于 SpringBoot + Vue 的 Web 商城应用
首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute): 函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。Fun: Fun 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API ...
讲真,这两个IDE插件,可以让你写出质量杠杠的代码
周末躺在床上看《拯救大兵瑞恩》 周末在闲逛的时候,发现了两个优秀的 IDE 插件,据说可以提高代码的质量,我就安装了一下,试了试以后发现,确实很不错,就推荐给大家。 01、Alibaba Java 代码规范插件 《阿里巴巴 Java 开发手册》,相信大家都不会感到陌生,其 IDEA 插件的下载次数据说达到了 80 万次,我今天又贡献了一次。嘿嘿。 该项目的插件地址: https://github....
Python+OpenCV实时图像处理
目录 1、导入库文件 2、设计GUI 3、调用摄像头 4、实时图像处理 4.1、阈值二值化 4.2、边缘检测 4.3、轮廓检测 4.4、高斯滤波 4.5、色彩转换 4.6、调节对比度 5、退出系统 初学OpenCV图像处理的小伙伴肯定对什么高斯函数、滤波处理、阈值二值化等特性非常头疼,这里给各位分享一个小项目,可通过摄像头实时动态查看各类图像处理的特点,也可对各位调参、测试...
2020年一线城市程序员工资大调查
人才需求 一线城市共发布岗位38115个,招聘120827人。 其中 beijing 22805 guangzhou 25081 shanghai 39614 shenzhen 33327 工资分布 2020年中国一线城市程序员的平均工资为16285元,工资中位数为14583元,其中95%的人的工资位于5000到20000元之间。 和往年数据比较: yea...
为什么猝死的都是程序员,基本上不见产品经理猝死呢?
相信大家时不时听到程序员猝死的消息,但是基本上听不到产品经理猝死的消息,这是为什么呢? 我们先百度搜一下:程序员猝死,出现将近700多万条搜索结果: 搜索一下:产品经理猝死,只有400万条的搜索结果,从搜索结果数量上来看,程序员猝死的搜索结果就比产品经理猝死的搜索结果高了一倍,而且从下图可以看到,首页里面的五条搜索结果,其实只有两条才是符合条件。 所以程序员猝死的概率真的比产品经理大,并不是错...
害怕面试被问HashMap?这一篇就搞定了!
声明:本文以jdk1.8为主! 搞定HashMap 作为一个Java从业者,面试的时候肯定会被问到过HashMap,因为对于HashMap来说,可以说是Java集合中的精髓了,如果你觉得自己对它掌握的还不够好,我想今天这篇文章会非常适合你,至少,看了今天这篇文章,以后不怕面试被问HashMap了 其实在我学习HashMap的过程中,我个人觉得HashMap还是挺复杂的,如果真的想把它搞得明明白...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
程序员如何通过造轮子走向人生巅峰?
前言:你所做的事情,也许暂时看不到成果。但不要灰心,你不是没有成长,而是在扎根。 程序员圈经常流行的一句话:“不要重复造轮子”。在计算机领域,我们将封装好的组件、库,叫做轮子。因为它可以拿来直接用,直接塞进我们的项目中,就能实现对应的功能。 有些同学会问,人家都已经做好了,你再来重新弄一遍,有什么意义?这不是在浪费时间吗。 殊不知,造轮子是一种学习方式,能快速进步,造得好,是自己超强能力的表...
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
阿里面试一个ArrayList我都能跟面试官扯半小时
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
良心推荐,我珍藏的一些Chrome插件
上次搬家的时候,发了一个朋友圈,附带的照片中不小心暴露了自己的 Chrome 浏览器插件之多,于是就有小伙伴评论说分享一下我觉得还不错的浏览器插件。 我下面就把我日常工作和学习中经常用到的一些 Chrome 浏览器插件分享给大家,随便一个都能提高你的“生活品质”和工作效率。 Markdown Here Markdown Here 可以让你更愉快的写邮件,由于支持 Markdown 直接转电子邮...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
Idea 中最常用的10款插件(提高开发效率),一定要学会使用!
学习使用一些插件,可以提高开发效率。对于我们开发人员很有帮助。这篇博客介绍了开发中使用的插件。
立即提问