hibernate cache配置问题

求各位大神帮忙..
WARN: HHH020003: Could not find a specific ehcache configuration for cache named [org.hibernate.cache.internal.StandardQueryCache]; using defaults.

 <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.use_query_cache">true</prop>
                <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
                <prop key="net.sf.ehcache.configurationResourceName">/cache/mycache.xml</prop>
            </props>
        </property>

mycache.xml

 <?xml version="1.0" encoding="UTF-8"?> 
<ehcache> 
    <diskStore path="f:\\cacheFile" />
    <defaultCache maxEntriesLocalHeap="10000" eternal="false"
        timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="false"
        maxEntriesLocalDisk="100000" memoryStoreEvictionPolicy="LFU" />
</ehcache>

POJO

 @Entity
@Table(name = "Customer")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Customer implements Serializable {
    .....
}

代码结构

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Spring3+hibernate4配置二级缓存的问题
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" destroy-method="destroy"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="mappingResources"> <list> <value>com/wjh/po/AfterPostPO.hbm.xml</value> <value>com/wjh/po/LogPO.hbm.xml</value> <value>com/wjh/po/PostPO.hbm.xml</value> <value>com/wjh/po/UserPO.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">false</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.generate_statistics">true</prop> <prop key="hibernate.cache.use_structured_entries">true</prop> <!-- <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory </prop> <prop key="net.sf.ehcache.configurationResourceName">ehcache.xml</prop> --> </props> </property> </bean> spring3+hibernate4 配置ehcache二级缓存只要一把上面的二级缓存配置的注释部分去掉,访问直接报错,而且两次错误不一样,重启tomcat第一次访问时候报的最终错误是: java.lang.ClassNotFoundException: org.hibernate.engine.jndi.JndiNameException 再访问一次报的最终错误是: java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cache.ehcache.EhCacheRegionFactory 是在是解决不了了,网上都搜遍了,大部分是hibernate3的配置,但是hibernate4的和hibernate3的不一样,也有hibernate4的配置,但是按照他们的都不行,大神门帮帮吧 slf4j-api-1.6.1.jar,hibernate-ehcache-4.3.4.Final.jar,ehcache-core-2.4.3.jar三个包已经导入了
hibernate的缓存配置问题
hibernate的缓存已经设置好了。。。。经过测试没有问题。。。 <ehcache> <diskStore path="D:\cache" /> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" /> <cache name="com.bat128.vo.db.Goods" maxElementsInMemory="800" eternal="false" overflowToDisk="false" timeToIdleSeconds="3600" timeToLiveSeconds="3600" /> </ehcache> 但是新手想问个问题。。设置缓存无非是想阻止客户频繁访问数据库造成压力。但是,适当的时候还是要刷新的。。。因此该如何配置时间间隔或者是缓存文件的大小呢。。。。 如果hibernate没有这种配置,那又该怎么办
有了Ehcache Annotations for Spring还需要配置org.hibernate.cache.EhCacheProvider吗?
问一个白痴问题。 有了Ehcache Annotations for Spring还需要配置org.hibernate.cache.EhCacheProvider吗?
关于springMVC+hibernate4+eacache二级缓存配置问题,启动一直报错
1、已经成功导入了相关jar包:hibernate-core 4.3.8Final;hibernate-ehcache 4.3.8Final和ehcache2.9.0 2、配置如下 <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSourceOne" /> <property name="hibernateProperties"> <props> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="javax.persistence.validation.mode">none</prop> <!-- 开启查询的二级缓存 如果不需要就不设置 --> <prop key="hibernate.cache.use_query_cache">true</prop> <!-- 开启二级缓存 ehcache --> <prop key="hibernate.cache.use_second_level_cache">true</prop> <!-- Hibernate4.0以上设置factory --> <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop> <!-- 二级缓存 ehcache的配置文件位置 --> <prop key="hibernate.cache.provider_configuration_file_resource_path">classpath:configs/ehcache.xml</prop> </props> </property> </bean> 其中也注意了hibernate4和3的区别了 3、在实体类以标签注入@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)后,启动项目会报错 4、错误如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'riskalertDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_riskalert' defined in class path resource [configs/spring-data-config.xml]: Invocation of init method failed; nested exception is org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath. ······ Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_riskalert' defined in class path resource [configs/spring-data-config.xml]: Invocation of init method failed; nested exception is org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath. ······ Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath. ······ 九月 12, 2017 2:58:18 下午 org.apache.catalina.core.StandardContext listenerStart 严重: Exception sending context initialized event to listener instance of class com.prosas.basic.utils.ProjectInit org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'riskalertDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_riskalert' defined in class path resource [configs/spring-data-config.xml]: Invocation of init method failed; nested exception is org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath. ······ Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_riskalert' defined in class path resource [configs/spring-data-config.xml]: Invocation of init method failed; nested exception is org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath. ······ Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath. ······ 5、网上查了很多资料,都说这个错误是<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>这行有问题,但是说的解决方法中都是改成这样啊,就是解决不了问题很苦恼,求大神解答!
SSH整合,hibernate注解配置,无hbm.xml,映射出现问题
java实体类代码: ``` package cn.com.car.base.entity; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; import org.hibernate.annotations.GenericGenerator; @Entity @Table(name="T_CAR") public class Car implements Serializable{ private static final long serialVersionUID = 1L; @GenericGenerator(name = "generator", strategy = "guid") @Id @GeneratedValue(generator = "generator") @Column(name = "id", unique = true, nullable = false, length = 38) private String id; @Column(name="models") private String models;//具体车型 @Column(name="type") private String type;//所属类别 @Column(name="price") private int price;//价格 public String getId() { return id; } public void setId(String id) { this.id = id; } public String getModels() { return models; } public void setModels(String models) { this.models = models; } public String getType() { return type; } public void setType(String type) { this.type = type; } public int getPrice() { return price; } public void setPrice(int price) { this.price = price; } @Override public String toString() { return "Car [id=" + id + ", models=" + models + ", type=" + type + ", price=" + price + "]"; } } ``` ------------------------------------------ application.xml配置 ``` <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" default-autowire="byName" default-lazy-init="true"> <!-- 属性文件读入 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath*:hibernate.properties</value> </list> </property> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${hibernate.connection.driverClassName}"/> <property name="url" value="${hibernate.connection.url}"/> <property name="username" value="${hibernate.connection.username}"/> <property name="password" value="${hibernate.connection.password}"/> </bean> <!--Hibernate SessionFatory--> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="annotatedClasses"> <list> <value>cn.com.car.base.entity.Car</value> </list> </property> <property name="hibernateProperties"> <value>classpath:hibernate.properties</value> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> </beans> ``` ---------------------------------------- hibernate.properties配置文件 ``` hibernate.show_sql=true hibernate.format_sql=false hibernate.cache=org.hibernate.cache.EhCacheProvider hibernate.dialect=org.hibernate.dialect.MySQL5Dialect hibernate.connection.driverClassName=com.mysql.jdbc.Driver hibernate.connection.url=jdbc:mysql://localhost:3306/car hibernate.connection.username=car hibernate.connection.password=123456 hibernate.c3p0.minPoolSize=5 hibernate.c3p0.maxPoolSize=50 hibernate.c3p0.timeout=1800 hibernate.c3p0.max_statement=200 ``` ---------------------------------- DAO层 ``` package cn.com.car.base.dao.impl; import java.util.HashMap; import java.util.List; import org.hibernate.Query; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import cn.com.car.base.dao.CarDao; import cn.com.car.base.entity.Car; public class CarDaoImpl extends HibernateDaoSupport implements CarDao { @Override public List<Car> getAllCar() { String sql="from T_CAR where 1=1"; List<Car> list=this.getHibernateTemplate().find(sql); return list; } @Override public List<Car> getCarByParam(HashMap<String, String> param) { StringBuilder sql=new StringBuilder(); sql.append("select * from T_CAR where 1=1"); if(param!=null){ if(param.get("type")!=null){ String type=param.get("type"); sql.append("and type="+type); } if(param.get("price")!=null){ String price=param.get("price"); sql.append("and price="+price); } Query query = this.getSession().createSQLQuery(sql.toString()); List<Car> list=query.list(); return list; } List<Car> list=this.getHibernateTemplate().find(sql.toString()); return list; } @Override public Car getCarByModels(String models) { String hql = "from T_CAR t where 1=1 " +" and t.models=? "; Query query = this.getSession().createQuery(hql).setString(0, models); return (Car) query.list().get(0); } @Override public Car getCarById(String id) { String hql = "from T_CAR t where 1=1 " +" and t.id=? "; Query query = this.getSession().createQuery(hql).setString(0, id); return (Car) query.list().get(0); } } ``` 我是模仿别的项目搭建的,没有.hbm.xml,现在运行DAO层就出现 “org.hibernate.hql.ast.QuerySyntaxException: T_CAR is not mapped [from T_CAR where 1=1]”这样的错误。
hibernate4.0.1使用二级缓存,出现NoCachingEnabledException: Second-level cache is not enab
在hibernate.cfg.xml中添加了 <property name="cache.use_second_level_cache">true</property> <property name="cache.provider_class">org.hibernate.cache.internal.OSCacheProvider</property> jar包也引入了。 在映射文件配置也添加了: <cache usage="read-write"/> 在hibernate3.3.2中使用2级缓存,是可以正常使用,但不知为何 在hibernate4.0.1中同样配置会出现: Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache] at org.hibernate.cache.internal.NoCachingRegionFactory.buildEntityRegion(NoCachingRegionFactory.java:68) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:339) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737) at com.hejian.hibernate.domain.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:18) ... 3 more 求解。
hibernate4.3二级缓存ehcache配置失败
java.lang.ExceptionInInitializerError at com.example.l_second_cache.App.buildSessionFactory(App.java:43) at com.example.l_second_cache.App.<clinit>(App.java:28) 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.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:195) at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.cache.spi.RegionFactory] at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:261) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:225) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:295) at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2444) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2440) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857) at com.example.l_second_cache.App.buildSessionFactory(App.java:37) ... 23 more Caused by: org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.internal.EhCacheRegionFactory] at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:101) at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:46) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:105) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:251) ... 30 more Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.cache.internal.EhCacheRegionFactory] as strategy [org.hibernate.cache.spi.RegionFactory] at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:128) at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:87) ... 33 more
Hibernate二级缓存 cache.xml问题
请问cache.xml配置中,diskStore这个节点可不可以不配置,如果不配置会有什么后果呢?
hibernate 2级缓存问题
今天在做一个更新操作时采用 HibernateTemplate 中这个方法this.getHibernateTemplate().bulkUpdate(hql, values); 做的时候发现更新后页面查询数据时候缓存没有并没有更新读是旧的数据.后换成this.hibernateTemplate.update(entity);发现在缓存数据更新了正常了.很想知道真正的原因是什么,不知道谁能给我个明确答案。 <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.cache.provider_class">com.googlecode.hibernate.memcached.MemcachedCacheProvider</prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.memcached.servers">localhost:11211</prop> 这里我的缓存部分配置。。。。。。。。。。。。。。。。
hibernate整合redis二级缓存问题
背景: 有一老项目采用的hibernate配合ehcache作为二级缓存,现因需求需要更换redis来做hibernate的二级缓存。大家不用问为什么不换掉hibernate,因为是老项目所以风险太大。 问题: 1、我按照网上做法导入了若干个jar包,见图: ![图片说明](https://img-ask.csdn.net/upload/201809/12/1536736237_134115.jpg) 2、spring中sessionFactory也配置了二级缓存: ``` hibernate.cache.use_query_cache = true hibernate.cache.use_second_level_cache = true hibernate.cache.use_structured_entries = true hibernate.cache.region_prefix = hibernate hibernate.cache.region.factory_class = org.hibernate.cache.redis.hibernate5.RedisRegionFactory hibernate.cache.provider_configuration_file_resource_path = hibernate-redis.properties ``` 3、也分别创建了hibernate-redis.properties和redisson.yaml,内容分别如下 (1)hibernate-redis.properties: ``` redisson-config = classpath:redisson.yaml redis.expiryInSeconds.default = 360 redis.expiryInSeconds.hibernate.common = 0 redis.expiryInSeconds.hibernate.account = 1200 ``` (2)redisson.yaml ``` singleServerConfig: idleConnectionTimeout: 10000 pingTimeout: 5000 connectTimeout: 5000 timeout: 5000 retryAttempts: 1 retryInterval: 1000 reconnectionTimeout: 3000 failedAttempts: 1 password: 123456 subscriptionsPerConnection: 3 clientName: null address: [ "redis://127.0.0.1:6379" ] subscriptionConnectionMinimumIdleSize: 1 subscriptionConnectionPoolSize: 3 connectionMinimumIdleSize: 3 connectionPoolSize: 3 database: 0 dnsMonitoring: false dnsMonitoringInterval: 5000 threads: 0 codec: !<org.redisson.codec.SnappyCodec> {} useLinuxNativeEpoll: false eventLoopGroup: null ``` 4、redis也正常运行 5、最后运行程序报了一个错: ``` Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.net.URI` out of START_ARRAY token at [Source: (URL); line: 14, column: 4] (through reference chain: org.redisson.config.Config["singleServerConfig"]->org.redisson.config.SingleServerConfig["address"]) at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63) at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1342) at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1138) at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromArray(StdDeserializer.java:674) at com.fasterxml.jackson.databind.deser.std.FromStringDeserializer.deserialize(FromStringDeserializer.java:164) at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:136) at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151) at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:127) at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2959) at org.redisson.config.ConfigSupport.fromYAML(ConfigSupport.java:169) at org.redisson.config.Config.fromYAML(Config.java:754) at org.hibernate.cache.redis.client.RedisClientFactory.createRedisClient(RedisClientFactory.java:63) ... 57 more ``` 不知道怎么解决了,希望有相关经验的大神能助我解惑。
如果为hibernate配置了二级缓存,如何查看缓存内容?
比如用jbosscache做二级缓存,如何才能看到二级缓存里的东东? [b]问题补充:[/b] 还是不知道hibernate的二级缓存如何能得到,比如通过lookup之类。 直接get的话前提是取得cache,现在甚至连hibernate创建cacheService的配置是怎样都不清楚,更不知道按什么key来保存了 [b]问题补充:[/b] 啊,我用的是jbosscache1.4.。。。。。 我记得jboss的wiki上推荐hibernate3.3以后的版本使用jbosscache2-3 hibernate3.2用1.4 我是参考http://www.jboss.org/community/docs/DOC-12948做的 所以木有这个类,用TreeCache也不成 [b]问题补充:[/b] public TreeCache(org.jboss.cache.TreeCache cache, String regionName... 构造函数的cache参数是我所得不到的。 我问题的关键也就是取得这个cache,而不是创建个新的 我有空查下源码ba,3q。
怪事,tomcat启动过程不读取hibernate配置文件
我在hibernate配置文件里面加了 <property name="hbm2ddl.auto">create</property> 没有效果,然后我随意修改配置文件的内容,比如把数据库密码改错掉,tomcat启动的时候居然没检查出来,这是怎么回事?最近遇到一大堆问题,郁闷死了 [b]问题补充:[/b] struts2 + hibernate 没有用spring,也没有用jndi [b]问题补充:[/b] 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">root</property> <property name="connection.pool_size">5</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="current_seccsion_context_class">thread</property> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <property name="show_sql">true</property> <property name="hbm2ddl.auto">create</property> <mapping resource="eshop/Items.hbm.xml"/> <mapping resource="eshop/User.hbm.xml"/> [b]问题补充:[/b] 那这么说来,不用spring,<property name="hbm2ddl.auto">create</property> 是不起作用的咯?
菜鸟问一个hibernate关于继承关系映射的配置问题
按照教学视频配置: <class name="Employee" discriminator-value = "0"> <id name="id"> <generator class="native"></generator> </id> <property name="name"/> <discriminator column = "type" type = "int"/> <many-to-one name="department" column = "depart_id"></many-to-one> <subclass name = "Skiller" discriminator-value = "1" > <property name = "skill"/> </subclass> <subclass name = "Sales" discriminator-value = "2" > <property name = "sell"/> </subclass> </class> 加了一个配置了subclass之后,就报错 元素类型为 "class" 的内容必须匹配 "`(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)"。` 按照官网上修改还是一样报错 不知道哪错了 刚接触hibernate,比较菜,希望各位大神不吝赐教
hibernate链接sqlite问题
![图片说明](https://img-ask.csdn.net/upload/201601/05/1451982007_14.png) ```方言 package com.free.core.dialect; /* * The author disclaims copyright to this source code. In place of * a legal notice, here is a blessing: * * May you do good and not evil. * May you find forgiveness for yourself and forgive others. * May you share freely, never taking more than you give. * */ import java.sql.Types; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.function.SQLFunctionTemplate; import org.hibernate.dialect.function.StandardSQLFunction; import org.hibernate.dialect.function.VarArgsSQLFunction; import org.hibernate.type.IntegerType; import org.hibernate.type.StringType; public class SQLiteDialect extends Dialect { public SQLiteDialect() { super(); registerColumnType(Types.BIT, "integer"); registerColumnType(Types.TINYINT, "tinyint"); registerColumnType(Types.SMALLINT, "smallint"); registerColumnType(Types.INTEGER, "integer"); registerColumnType(Types.BIGINT, "bigint"); registerColumnType(Types.FLOAT, "float"); registerColumnType(Types.REAL, "real"); registerColumnType(Types.DOUBLE, "double"); registerColumnType(Types.NUMERIC, "numeric"); registerColumnType(Types.DECIMAL, "decimal"); registerColumnType(Types.CHAR, "char"); registerColumnType(Types.VARCHAR, "varchar"); registerColumnType(Types.LONGVARCHAR, "longvarchar"); registerColumnType(Types.DATE, "date"); registerColumnType(Types.TIME, "time"); registerColumnType(Types.TIMESTAMP, "timestamp"); registerColumnType(Types.BINARY, "blob"); registerColumnType(Types.VARBINARY, "blob"); registerColumnType(Types.LONGVARBINARY, "blob"); // registerColumnType(Types.NULL, "null"); registerColumnType(Types.BLOB, "blob"); registerColumnType(Types.CLOB, "clob"); registerColumnType(Types.BOOLEAN, "integer"); registerFunction("concat", new VarArgsSQLFunction(StringType.INSTANCE, "", "||", "")); registerFunction("mod", new SQLFunctionTemplate(IntegerType.INSTANCE, "?1 % ?2")); registerFunction("substr", new StandardSQLFunction("substr", StringType.INSTANCE)); registerFunction("substring", new StandardSQLFunction("substr", StringType.INSTANCE)); } public boolean supportsIdentityColumns() { return true; } /* public boolean supportsInsertSelectIdentity() { return true; // As specify in NHibernate dialect } */ public boolean hasDataTypeInIdentityColumn() { return false; // As specify in NHibernate dialect } /* public String appendIdentitySelectToInsert(String insertString) { return new StringBuffer(insertString.length()+30). // As specify in NHibernate dialect append(insertString). append("; ").append(getIdentitySelectString()). toString(); } */ public String getIdentityColumnString() { // return "integer primary key autoincrement"; return "integer"; } public String getIdentitySelectString() { return "select last_insert_rowid()"; } public boolean supportsLimit() { return true; } public String getLimitString(String query, boolean hasOffset) { return new StringBuffer(query.length() + 20).append(query).append( hasOffset ? " limit ? offset ?" : " limit ?").toString(); } public boolean supportsTemporaryTables() { return true; } public String getCreateTemporaryTableString() { return "create temporary table if not exists"; } public boolean dropTemporaryTableAfterUse() { return false; } public boolean supportsCurrentTimestampSelection() { return true; } public boolean isCurrentTimestampSelectStringCallable() { return false; } public String getCurrentTimestampSelectString() { return "select current_timestamp"; } public boolean supportsUnionAll() { return true; } public boolean hasAlterTable() { return false; // As specify in NHibernate dialect } public boolean dropConstraints() { return false; } public String getAddColumnString() { return "add column"; } public String getForUpdateString() { return ""; } public boolean supportsOuterJoinForUpdate() { return false; } public String getDropForeignKeyString() { throw new UnsupportedOperationException( "No drop foreign key syntax supported by SQLiteDialect"); } public String getAddForeignKeyConstraintString(String constraintName, String[] foreignKey, String referencedTable, String[] primaryKey, boolean referencesPrimaryKey) { throw new UnsupportedOperationException( "No add foreign key syntax supported by SQLiteDialect"); } public String getAddPrimaryKeyConstraintString(String constraintName) { throw new UnsupportedOperationException( "No add primary key syntax supported by SQLiteDialect"); } public boolean supportsIfExistsBeforeTableName() { return true; } public boolean supportsCascadeDelete() { return false; } /** * 修复分页bug * @author Z.kc */ @Override public boolean bindLimitParametersInReverseOrder() { return true; } } ``` ```配置 <?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> <!-- Database connection settings --> <property name="connection.driver_class">org.sqlite.JDBC</property> <property name="connection.url">jdbc:sqlite:D:/test.db</property> <property name="connection.username"></property> <property name="connection.password"></property> <!-- JDBC connection pool (use the built-in) --> <property name="c3p0.min_size">0</property> <property name="c3p0.max_size">15</property> <property name="c3p0.timeout">1800</property> <!-- 当连接池耗尽时,一次获得连接数--> <property name="c3p0.acquire_increment">1</property> <property name="c3p0.max_statements">0</property> <!-- 当连接池连接耗尽时,客户端getConnection(),所等待的时间--> <property name="c3p0.idle_test_period">120</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Configuration information --> <property name="dialect">com.free.core.dialect.SQLiteDialect</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="hibernate.show_sql">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">update</property> <property name="javax.persistence.validation.mode">none</property> <!-- Mapping entity class --> <mapping class="com.free.system.model.Depart" /> <mapping class="com.free.system.model.User" /> <mapping class="com.free.system.model.Role" /> </session-factory> </hibernate-configuration> ```
spring3 + hibernate 4.1 配置的问题
项目用:spring MVC + spring 3.2.4 + Hibernate 4.2.6+spring security3.1.4 在启动容器时,spring security 通过hibernate去数据库加载权限时,报:No Session found for current thread异常。 异常如下: [code="java"] Caused by: org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97) at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:990) at com.seveng.weixin.foundation.dao.support.HibernateGenericDao.getSession(HibernateGenericDao.java:58) at com.seveng.weixin.foundation.dao.support.HibernateGenericDao.getAll(HibernateGenericDao.java:85) at com.seveng.weixin.foundation.security.filter.support.WeixinInvocationSecurityMetadataSourceService.loadResourceDefine(WeixinInvocationSecurityMetadataSourceService.java:39) 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 org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:344) at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:295) at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:130) ... 60 more [/code] spring MVC 配置文件:spring-mvc.xml [code="xml"] <mvc:annotation-driven /> <!-- 开启controller注解支持 --> <context:component-scan base-package="com.seveng.weixin" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> [/code] spring 主配置文件: [code="xml"] <context:component-scan base-package="com.seveng.weixin"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> [/code] 事务的配置: [code="xml"] <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="create*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="merge*" propagation="REQUIRED" /> <tx:method name="del*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="put*" propagation="REQUIRED" /> <tx:method name="use*" propagation="REQUIRED" /> <!--hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到 --> <tx:method name="get*" propagation="REQUIRED" read-only="true" /> <tx:method name="load*" propagation="REQUIRED" read-only="true" /> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="list*" propagation="REQUIRED" read-only="true" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> <aop:config proxy-target-class="true"> <!-- 对业务逻辑层实施事务 --> <aop:pointcut id="txPointcut" expression="execution(* com.seveng.weixin..service.impl.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" /> </aop:config> <aop:aspectj-autoproxy expose-proxy="true"/> <tx:annotation-driven transaction-manager="txManager" proxy-target-class="true" /> [/code] 数据库数相关配置: [code="xml"] <!-- 加载资源文件 --> <context:property-placeholder location="classpath:config/database.properties" /> <!-- 数据库映射 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${connection.driver_class}" /> <property name="url" value="${connection.url}" /> <property name="username" value="${connection.username}" /> <property name="password" value="${connection.password}" /> </bean> <!-- hibernate 需要的信息 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="packagesToScan"> <list> <value>com.seveng.weixin.**.model.*</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.query.substitutions">${hibernate.query.substitutions}</prop> <prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop> <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop> <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop> <prop key="hibernate.bytecode.use_reflection_optimizer">${hibernate.bytecode.use_reflection_optimizer}</prop> <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop> <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop> <prop key="hibernate.cache.use_structured_entries">${hibernate.cache.use_structured_entries}</prop> <prop key="net.sf.ehcache.configurationResourceName">${net.sf.ehcache.configurationResourceName}</prop> <prop key="hibernate.current_session_context_class">${hibernate.current_session_context_class}</prop> </props> </property> </bean> [/code] spring security 相关配置: [code="xml"] <!-- 不拦截的请求 --> <security:http pattern="/login" security="none" /> <security:http pattern="/images/**" security="none" /> <security:http pattern="/css/**" security="none" /> <security:http pattern="/js/**" security="none" /> <!-- 保护应用程序的所有URL --> <security:http auto-config="true"> <!-- login-page: 指定登录页面 --> <security:form-login login-page="/login" /> <security:logout logout-success-url="/login" /> <!-- 会话管理配置 ,设置最多登录一次,二次登录会让第一次登录失效, 则设置error-if-maximum-exceeded为false,要求第一次有效设置为true --> <security:session-management invalid-session-url="/login"> <security:concurrency-control max-sessions="1" error-if-maximum-exceeded="false" /> </security:session-management> <!-- 增加一个自定义的filter,放在FILTER_SECURITY_INTERCEPTOR之前, 实现用户、角色、权限、资源的数据库管理。 --> <security:custom-filter ref="weixinFilter" before="FILTER_SECURITY_INTERCEPTOR" /> </security:http> <!-- 一个自定义的filter,必须包含authenticationManager, accessDecisionManager,securityMetadataSource三个属性。 --> <bean id="weixinFilter" class="com.seveng.weixin.foundation.security.filter.WeixinFilterSecurityInterceptor"> <property name="authenticationManager" ref="authenticationManager" /> <property name="accessDecisionManager" ref="weixinAccessDecisionManager" /> <property name="securityMetadataSource" ref="weixinInvocationSecurityMetadataSourceService" /> </bean> <!-- 注意能够为authentication-manager 设置alias别名 --> <security:authentication-manager alias="authenticationManager"> <security:authentication-provider user-service-ref="appUserDetailsService"> <security:password-encoder ref="passwordEncoder"> <security:salt-source user-property="username" /> </security:password-encoder> </security:authentication-provider> </security:authentication-manager> <!-- 事件监听:实现了 ApplicationListener监听接口,包括AuthenticationCredentialsNotFoundEvent 事件, AuthorizationFailureEvent事件,AuthorizedEvent事件, PublicInvocationEvent事件 --> <bean class="org.springframework.security.authentication.event.LoggerListener" /> <!-- 用户的密码加密或解密 --> <bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" /> <!-- 启用用户的缓存功能 --> <bean id="userCache" class="org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache"> <property name="cache" ref="userEhCache" /> </bean> <bean id="userEhCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean"> <property name="cacheName" value="userCache" /> <property name="cacheManager" ref="cacheManager" /> </bean> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" > <property name="configLocation" value="classpath:config/ehcache.xml" /> </bean> [/code] 当容器启动时,spring security加载权限的代码 [code="java"] @PostConstruct @Transactional public void loadResourceDefine() { List<Authority> authorities = this.getAll(Authority.class); // 应当是资源为key, 权限为value。 资源通常为url, 权限就是那些以ROLE_为前缀的角色。 一个资源可以由多个权限来访问。 resourceMap = new HashMap<String, Collection<ConfigAttribute>>(); for (Authority auth : authorities) { ConfigAttribute ca = new SecurityConfig(auth.getAuthName()); Set<Resource> resources = auth.getResources(); for (Resource res : resources) { String url = res.getResString(); // 判断资源文件和权限的对应关系,如果已经存在相关的资源url,则要通过该url为key提取出权限集合,将权限增加到权限集合中 if (resourceMap.containsKey(url)) { Collection<ConfigAttribute> value = resourceMap.get(url); value.add(ca); resourceMap.put(url, value); } else { Collection<ConfigAttribute> atts = new ArrayList<ConfigAttribute>(); atts.add(ca); resourceMap.put(url, atts); } } } } [/code]
一个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缓存同步问题
环境: OS : Win XP SP2 Hibernate: 3.5.1 伪代码: [code="java"] System.out.println(StringUtils.center("query 查询: " )); Session session = HibernateSessionFactory.getSession(); String hql = "FROM Room T WHERE T.address = ?"; Query query = session.createQuery(hql).setParameter(0, "Shanghai"); query.setCacheable(true); Room room = (Room) query.list().get(0); HibernateSessionFactory.closeSession(); System.out.println(StringUtils.center("更新: " )); Session session2 = HibernateSessionFactory.getSession(); Transaction tx = session2.beginTransaction(); room.setSize(60); session2.update(room); tx.commit(); HibernateSessionFactory.closeSession(); System.out.println(StringUtils.center("load查询(已同步缓存): " )); Session session3 = HibernateSessionFactory.getSession(); room = (Room) session3.load(Room.class, new Long(2)); Hibernate.initialize(room); HibernateSessionFactory.closeSession(); System.out.println(room.getSize()); System.out.println(StringUtils.center("query 查询(未同步缓存): ")); Session session4 = HibernateSessionFactory.getSession(); query = session4.createQuery(hql).setParameter(0, "Shanghai"); query.setCacheable(true); room = (Room) query.list().get(0); HibernateSessionFactory.closeSession(); [/code] [size=xx-large]hibernate.cache.use_query_cache 和 <cache usage="read-write" /> 和 setCacheable(true) 都已配置过 疑问: 两次查询条件都一样, 中间修改了实体, 为什么第二次query查询还是发送了sql, 如果同步了缓存应该不会发送, 请指教. 谢谢.[/size]
hibernate 的缓存使用问题
问题描述见: 在测试Hibernate二级缓存的时候 把ehcache.xml和hibernate.cfg.xml里的相关二级缓存的配置 都删掉 , 直接在hbm.xml中配置 <cache usage= "read-write " /> , 发现查询结果看起来仍是通过缓存来查询的 因为sql没有打印两次 [code="java"] package com.vavi.test; import org.hibernate.Session; import com.vavi.dao.HibernateSessionFactory; import com.vavi.pojo.Tuser; public class Test { public static void main(String[] args) { Session sess = HibernateSessionFactory.getCurrentSession(); Tuser user_load = (Tuser) sess.load(com.vavi.pojo.Tuser.class, new Long(1)); System.out.println(user_load.getName()); sess.close(); sess = HibernateSessionFactory.getCurrentSession(); Tuser user_get = (Tuser) sess.get(com.vavi.pojo.Tuser.class, new Long(1)); System.out.println(user_get.getName()); sess.close(); } } [/code] HibernateSessionFactory 是MyEclipse 生成的 [b]问题补充:[/b] package com.vavi.test; /** * 结论:Session级别的缓存 仅在当前session 生命期内有效 * 一旦该session关闭 ,再次查询时仍需要访问数据库 */ import org.hibernate.Session; import com.vavi.dao.HibernateSessionFactory; import com.vavi.pojo.Tuser; public class Test_SessionClose { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Session sess = HibernateSessionFactory.getCurrentSession(); Tuser user_load =(Tuser) sess.load(com.vavi.pojo.Tuser.class, new Long(1)); System.out.println(user_load.getName()); sess.close(); sess = HibernateSessionFactory.getCurrentSession(); Tuser user_get =(Tuser) sess.get(com.vavi.pojo.Tuser.class, new Long(1)); System.out.println(user_get.getName()); sess.close(); } } 这段代码跟上面的一样 唯一 不同的地方就是 不在 Tuser.hbm.xml 加上 <cache usage="read-write" /> 这时候打印的结果是 : Hibernate: select tuser0_.ID as ID0_, tuser0_.NAME as NAME0_0_, tuser0_.AGE as AGE0_0_ from GHJ.TUSER tuser0_ where tuser0_.ID=? ghj Hibernate: select tuser0_.ID as ID0_, tuser0_.NAME as NAME0_0_, tuser0_.AGE as AGE0_0_ from GHJ.TUSER tuser0_ where tuser0_.ID=? ghj 说明session cache 还是失效了的 按照您的说法 我打印了下 System.out.println("session:"+sess); 这两个程序(加不加 <cache usage="read-write" /> )都是 session:org.hibernate.impl.SessionImpl(<closed>) 根据这个打印结果并不能看出什么 所以关键是 这段话 <cache usage="read-write" /> 不太清楚 他到底有什么作用 应该不是 一级缓存 二级缓存 或 查询缓存 最后谢谢您的解答 ^^ [b]问题补充:[/b] 多谢gotothework的 回答 你说的这几种策略我也知道 但是关键是加上这段话后 <cache usage="read-write" /> 不需要访问数据库 就可以直接出现结果了 (详细描述见上) 而我认为 这个查询结果不是 一级缓存 二级缓存 或 查询缓存 里面的内容 但是如果不是 hibernate 又是如何管理这部分缓存的 抑或还是我的理解有误? [b]问题补充:[/b] To gotothework : 在调用sess.close()这个方法以前,一级缓存是一直有效的.所以应该是由一级缓存里调用出来的. 当你查询时,会首先从一级缓存中寻找,如果查找不到,还会从二级缓存中寻找,如果还未找到,就会从数据库中查询. 我明白 你见我第二个问题补充,现在问题是 其他配置(二级缓存 查询缓存 都不配置),仅在Tuser.hbm.xml 加上 <cache usage="read-write" /> 打印结果表明: 第二次查询结果 没有访问数据库 就直接返回结果了 [b]问题补充:[/b] To gotothework : 在您说的这种情况下 hibernate是使用哪种缓存呢? 一级缓存? 但是如果同样的程序 不在 Tuser.hbm.xml 加上 <cache usage="read-write" /> 仍是需要先后访问两次数据库的 所以这段 <cache usage="read-write" /> 代码作用很诡异 难道加了这段话就保存了一级缓存的数据? 您说的openSession() 我试了下 同时加上了 sess.contains(user_load) 和hashCode() 这个方法 package com.vavi.dao; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; //import com.vavi.dao.HibernateSessionFactory; import com.vavi.pojo.Tuser; public class SFTest { public static void main(String[] args) { SessionFactory sf = new Configuration().configure().buildSessionFactory(); Session sess = sf.openSession(); System.out.println(sess.hashCode()); Tuser user_load = (Tuser) sess.load(com.vavi.pojo.Tuser.class, new Long(1)); System.out.println("sess.contains user_load? "+sess.contains(user_load)); System.out.println(user_load.getName()); sess.close(); System.out.println("sess.contains user_load? "+sess.contains(user_load)); sess =sf.openSession(); System.out.println(sess.hashCode()); Tuser user_get = (Tuser) sess.get(com.vavi.pojo.Tuser.class, new Long(1)); System.out.println("sess.contains user_load? "+sess.contains(user_load)); System.out.println("sess.contains user_get? "+sess.contains(user_get)); System.out.println(user_get.getName()); sess.close(); System.out.println("sess.contains user_get? "+sess.contains(user_get)); } } 打印结果如下: 31966667 sess.contains user_load? true Hibernate: select tuser0_.ID as ID0_, tuser0_.NAME as NAME0_0_, tuser0_.AGE as AGE0_0_ from GHJ.TUSER tuser0_ where tuser0_.ID=? ghj sess.contains user_load? false 22375698 sess.contains user_load? false sess.contains user_get? true ghj sess.contains user_get? false 所以这个现象就比较诡异了 发现sess关闭后,sess.contains(user_load)返回值是false的。 但是仍未查询数据库就获得结果了 [b]问题补充:[/b] 哈哈 问题搞定 忘了hibernate 是默认启动二级缓存 以及使用 Cache provider: org.hibernate.cache.EhCacheProvider. 我上述的问题现象其实还是使用Hibernate的 二级缓存的 [main] (SettingsFactory.java:209) - Second-level cache: enabled INFO [main] (SettingsFactory.java:213) - Query cache: disabled INFO [main] (SettingsFactory.java:321) - Cache provider: org.hibernate.cache.EhCacheProvider INFO [main] (SettingsFactory.java:228) - Optimize cache for minimal puts: disabled INFO [main] (SettingsFactory.java:237) - Structured second-level cache entries: disabled 总结: 1、使用二级缓存的话 仅仅必须在 Tuser.hbm.xml 加上 <cache usage="read-write" /> 其他设置使用的是Hibernate 里面jar包的默认配置文件 当然如果需要高级应用,那就需要自定义配置文件了 2、对于Hibernate,遇到不明白的问题,建议加上<property name="generate_statistics">true</property> 并打印debug级别日志 3、Session sess = HibernateSessionFactory.getCurrentSession(); 仍是获得新的session 实例的 同时 一级缓存(Session Cache)是在session.close() 调用后就失效的,跟当前没关系 (不知道理解有没有问题) 4、没有莫名其妙的问题,想起老大对我说的一句公告。 哈哈 ,这就是我中秋节的礼物了 ^^
struts2.3spring4.1hibernate4.3的集成问题
Error configuring application listener of class org.springframework.web.util.Log4jConfigListener java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener Error configuring application listener of class org.springframework.web.context.request.RequestContextListener java.lang.ClassNotFoundException: org.springframework.web.context.request.RequestContextListener spring-web放在WEB-INF/lib下路径是问题的,不知道哪里出错 ``` <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>S2316S411H436</display-name> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log4j.properties</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>struts2Filter</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>hibernate4Filter</filter-name> <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>hibernate4Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app> ``` ``` <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> <!-- 说明:下面有的Bean配置提供了多种方案,请根据需要采用某一种(别忘了注释掉其他同类方案) --> <!-- 自动扫描Spring注解配置 --> <context:component-scan base-package="com" /> <!-- 自动加载属性配置文件 --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 配置数据源:方法一,使用C3P0方式(推荐) --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" p:driverClass="${jdbc.driverClassName}" p:jdbcUrl="${jdbc.url}" p:user="${jdbc.username}" p:password="${jdbc.password}" /> <!-- 配置数据源:方法二,使用DBCP方式(不推荐) --> <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}" /> --> <!-- 配置数据源:方法三,使用JNDI方式 --> <!-- <jee:jndi-lookup id="dataSource" jndi-name="${jndi.name}" /> --> <!-- 配置Hibernate的数据源代理工厂:方法一,使用p属性通配符,按文件名搜索匹配的映射文件 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" p:dataSource-ref="dataSource" p:mappingLocations="classpath*:/com/**/*.hbm.xml"> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop> </props> </property> </bean> <!-- 配置Hibernate的数据源代理工厂:方法二,使用list集合,按文件名搜索匹配的映射文件 --> <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" p:dataSource-ref="dataSource"> <property name="mappingLocations"> <list> <value>classpath*:/com/**/*.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop> </props> </property> </bean> --> <!-- 配置Hibernate的数据源代理工厂:方法三,使用p属性通配符,按目录搜索映射文件 --> <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" p:dataSource-ref="dataSource" p:mappingDirectoryLocations="classpath*:/com/**/domain"> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop> </props> </property> </bean> --> <!-- 配置Hibernate的数据源代理工厂:方法四,使用hibernate.cfg.xml --> <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" p:dataSource-ref="dataSource" p:configLocation="classpath:hibernate.cfg.xml"> </bean> --> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory" /> <!-- 配置声明式事务:方法一,在Service实现类或者public实现方法上使用注解@Transactional,则此类或方法就会启用事务机制 --> <tx:annotation-driven transaction-manager="transactionManager" /> <!-- 配置声明式事务:方法二,使用tx/aop命名空间的配置(其实还有方法三,由于快要过时不推荐使用了,这里就不给出方法三的配置了) --> <!-- <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="edit*" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="new*" propagation="REQUIRED" /> <tx:method name="set*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="change*" propagation="REQUIRED" /> <tx:method name="get*" propagation="REQUIRED" read-only="true" /> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="load*" propagation="REQUIRED" read-only="true" /> <tx:method name="search*" propagation="REQUIRED" read-only="true" /> <tx:method name="*" propagation="REQUIRED" read-only="true" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="mypointcut" expression="execution(* com.**.service..*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="mypointcut" /> </aop:config> --> <!-- 下面三个Bean的配置可有可无,但配置后用处更大,通常用于BaseDao类、其他Dao类或特殊工具类中 --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate" p:sessionFactory-ref="sessionFactory" /> <bean id="hibernateDaoSupport" class="org.springframework.orm.hibernate4.support.HibernateDaoSupport" p:hibernateTemplate-ref="hibernateTemplate" abstract="true"/> <bean id="sessionFactoryUtils" class="org.springframework.orm.hibernate4.SessionFactoryUtils" abstract="true"/> </beans> ```
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过...
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我...
2019年还剩1天,我从外包公司离职了
这日子过的可真快啊,2019年还剩1天,外包公司干了不到3个月,我离职了
《面试宝典》2019年springmvc面试高频题(java)
前言 2019即将过去,伴随我们即将迎来的又是新的一年,过完春节,马上又要迎来新的金三银四面试季。那么,作为程序猿的你,是否真的有所准备的呢,亦或是安于本职工作,继续做好手头上的事情。 当然,不论选择如何,假如你真的准备在之后的金三银四跳槽的话,那么作为一个Java工程师,就不可不看了。如何在几个月的时间里,快速的为即将到来的面试进行充分的准备呢? 1、什么是Spring MVC ?简单...
计算机网络的核心概念
这是《计算机网络》系列文章的第二篇文章 我们第一篇文章讲述了计算机网络的基本概念,互联网的基本名词,什么是协议以及几种接入网以及网络传输的物理媒体,那么本篇文章我们来探讨一下网络核心、交换网络、时延、丢包、吞吐量以及计算机网络的协议层次和网络攻击。 网络核心 网络的核心是由因特网端系统和链路构成的网状网络,下面这幅图正确的表达了这一点 那么在不同的 ISP 和本地以及家庭网络是如何交换信息的呢?...
python自动下载图片
近日闲来无事,总有一种无形的力量萦绕在朕身边,让朕精神涣散,昏昏欲睡。 可是,像朕这么有职业操守的社畜怎么能在上班期间睡瞌睡呢,我不禁陷入了沉思。。。。 突然旁边的IOS同事问:‘嘿,兄弟,我发现一个网站的图片很有意思啊,能不能帮我保存下来提升我的开发灵感?’ 作为一个坚强的社畜怎么能说自己不行呢,当时朕就不假思索的答应:‘oh, It’s simple. Wait for me a few
一名大专同学的四个问题
【前言】   收到一封来信,赶上各种事情拖了几日,利用今天要放下工作的时机,做个回复。   2020年到了,就以这一封信,作为开年标志吧。 【正文】   您好,我是一名现在有很多困惑的大二学生。有一些问题想要向您请教。   先说一下我的基本情况,高考失利,不想复读,来到广州一所大专读计算机应用技术专业。学校是偏艺术类的,计算机专业没有实验室更不用说工作室了。而且学校的学风也不好。但我很想在计算机领...
复习一周,京东+百度一面,不小心都拿了Offer
京东和百度一面都问了啥,面试官百般刁难,可惜我全会。
20道你必须要背会的微服务面试题,面试一定会被问到
写在前面: 在学习springcloud之前大家一定要先了解下,常见的面试题有那块,然后我们带着问题去学习这个微服务技术,那么就会更加理解springcloud技术。如果你已经学了springcloud,那么在准备面试的时候,一定要看看看这些面试题。 文章目录1、什么是微服务?2、微服务之间是如何通讯的?3、springcloud 与dubbo有哪些区别?4、请谈谈对SpringBoot 和S...
Java 14 都快来了,为什么还有这么多人固守Java 8?
从Java 9开始,Java版本的发布就让人眼花缭乱了。每隔6个月,都会冒出一个新版本出来,Java 10 , Java 11, Java 12, Java 13, 到2020年3月份,...
轻松搭建基于 SpringBoot + Vue 的 Web 商城应用
首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute): 函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。Fun: Fun 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API ...
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个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
python爬取百部电影数据,我分析出了一个残酷的真相
2019年就这么匆匆过去了,就在前几天国家电影局发布了2019年中国电影市场数据,数据显示去年总票房为642.66亿元,同比增长5.4%;国产电影总票房411.75亿元,同比增长8.65%,市场占比 64.07%;城市院线观影人次17.27亿,同比增长0.64%。 看上去似乎是一片大好对不对?不过作为一名严谨求实的数据分析师,我从官方数据中看出了一点端倪:国产票房增幅都已经高达8.65%了,为什...
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
阿里面试一个ArrayList我都能跟面试官扯半小时
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
2020年1月中国编程语言排行榜,python是2019增长最快编程语言
编程语言比例 排名 编程语言 最低工资 工资中位数 最低工资 最高工资 人头 人头百分比 1 rust 20713 17500 5042 46250 480 0.14% 2 typescript 18503 22500 6000 30000 1821 0.52% 3 lua 18150 17500 5250 35000 2956 0.84% 4 go 17989 16...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
Idea 中最常用的10款插件(提高开发效率),一定要学会使用!
学习使用一些插件,可以提高开发效率。对于我们开发人员很有帮助。这篇博客介绍了开发中使用的插件。
AI 没让人类失业,搞 AI 的人先失业了
最近和几个 AI 领域的大佬闲聊 根据他们讲的消息和段子 改编出下面这个故事 如有雷同 都是巧合 1. 老王创业失败,被限制高消费 “这里写我跑路的消息实在太夸张了。” 王葱葱哼笑一下,把消息分享给群里。 阿杰也看了消息,笑了笑。在座几位也都笑了。 王葱葱是个有名的人物,21岁那年以全额奖学金进入 KMU 攻读人工智能博士,累计发表论文 40 余篇,个人技术博客更是成为深度学习领域内风向标。 ...
立即提问