- 浏览: 212498 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
springmvc_springjpa:
spring mvc demo教程源代码下载,地址:http: ...
SpringMVC初探_(1) -
LinApex:
测试,如何看性能,如何评比各种服务器,你也写篇日志呗
压力测试 (LoadRunner+Websphere +Tomcat) -
tanying2869:
没找到附件
集成struts2 spring hibernate,使用注解 -
xiaotao.2010:
ranwei09321115 写道晕 不是免费的!...我也发 ...
各种免费的Webservice接口 -
xiaotao.2010:
gaoxingang2008 写道这些方法 都用了 还是不行呀 ...
禁用浏览器后退按钮
不细说了直接上代码
代码中的注释可以参考Hibernate-学习笔记01
1、hibernate.cfg.xml
<?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.username">its</property> <property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property> <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property> <property name="connection.password">its</property> <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="current_session_context_class">thread</property> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="hbm2ddl.auto">update</property> <!-- 配饰AnnotationConfiguration时使用的 --> <mapping class="com.scal.entity.Teacher"/> </session-factory> </hibernate-configuration>
2、log4j.properties
### direct log messages to stdout ### log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n ### set log levels - for more verbose logging change 'info' to 'debug' ### log4j.rootLogger=warn, stdout #log4j.logger.org.hibernate=info #log4j.logger.org.hibernate=debug ### log HQL query parser activity #log4j.logger.org.hibernate.hql.ast.AST=debug ### log just the SQL #log4j.logger.org.hibernate.SQL=debug ### log JDBC bind parameters ### ###log4j.logger.org.hibernate.type=info #log4j.logger.org.hibernate.type=debug ### log schema export/update ### log4j.logger.org.hibernate.tool.hbm2ddl=debug ### log HQL parse trees #log4j.logger.org.hibernate.hql=debug ### log cache activity ### #log4j.logger.org.hibernate.cache=debug ### log transaction activity #log4j.logger.org.hibernate.transaction=debug ### log JDBC resource acquisition #log4j.logger.org.hibernate.jdbc=debug ### enable the following line if you want to track down connection ### ### leakages when using DriverManagerConnectionProvider ### #log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
3、HibernateSessionFactory
package com.scal.entity; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.Configuration; /** * Configures and provides access to Hibernate sessions, tied to the * current thread of execution. Follows the Thread Local Session * pattern, see {@link http://hibernate.org/42.html }. */ public class HibernateSessionFactory { /** * Location of hibernate.cfg.xml file. * Location should be on the classpath as Hibernate uses * #resourceAsStream style lookup for its configuration file. * The default classpath location of the hibernate config file is * in the default package. Use #setConfigFile() to update * the location of the configuration file for the current session. */ private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml"; private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>(); private static Configuration configuration = new Configuration(); private static org.hibernate.SessionFactory sessionFactory; private static String configFile = CONFIG_FILE_LOCATION; static { try { /* 使用配置文件的获取config */ configuration.configure(configFile); sessionFactory = configuration.buildSessionFactory(); } catch (Exception e) { try{ /* 使用注解的获取config */ configuration = new AnnotationConfiguration().configure(); sessionFactory = configuration.buildSessionFactory(); }catch (Exception es) { System.err.println("%%%% Error Creating SessionFactory %%%%"); es.printStackTrace(); } } } private HibernateSessionFactory() { } /** * Returns the ThreadLocal Session instance. Lazy initialize * the <code>SessionFactory</code> if needed. * * @return Session * @throws HibernateException */ public static Session getSession() throws HibernateException { Session session = (Session) threadLocal.get(); if (session == null || !session.isOpen()) { if (sessionFactory == null) { rebuildSessionFactory(); } session = (sessionFactory != null) ? sessionFactory.openSession() : null; threadLocal.set(session); } return session; } /** * Rebuild hibernate session factory * */ public static void rebuildSessionFactory() { try { configuration.configure(configFile); sessionFactory = configuration.buildSessionFactory(); } catch (Exception e) { System.err .println("%%%% Error Creating SessionFactory %%%%"); e.printStackTrace(); } } /** * Close the single hibernate session instance. * * @throws HibernateException */ public static void closeSession() throws HibernateException { Session session = (Session) threadLocal.get(); threadLocal.set(null); if (session != null) { session.close(); } } /** * return session factory * */ public static org.hibernate.SessionFactory getSessionFactory() { return sessionFactory; } /** * return session factory * * session factory will be rebuilded in the next call */ public static void setConfigFile(String configFile) { HibernateSessionFactory.configFile = configFile; sessionFactory = null; } /** * return hibernate configuration * */ public static Configuration getConfiguration() { return configuration; } }
4、Teacher (基于注解的实体)
package com.scal.entity; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.SequenceGenerator; @Entity public class Teacher implements Serializable{ private static final long serialVersionUID = 729474527745209202L; @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="TEACHER_SEQ") @SequenceGenerator(name="TEACHER_SEQ",allocationSize=1,initialValue=1, sequenceName="TEACHER_SEQ") private Long id; private String name; private String age; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public static long getSerialVersionUID() { return serialVersionUID; } }
5、DoTest
package com.scal.run; import org.hibernate.Session; import org.hibernate.SessionFactory; import com.scal.entity.HibernateSessionFactory; import com.scal.entity.Teacher; public class DoTest { public static void main(String[] args) { SessionFactory sf= HibernateSessionFactory.getSessionFactory(); Session session = sf.getCurrentSession(); Teacher teacher = new Teacher(); teacher.setAge("10"); teacher.setName("tom"); session.beginTransaction(); session.save(teacher); session.getTransaction().commit(); sf.close(); } }
发表评论
-
键码(KeyCode)
2013-02-28 16:32 18856字母和数字键的键码值(keyCode) 按键 键 ... -
1111111
2012-08-24 14:35 0{id=news_ln_statistics, categor ... -
my aa
2012-07-18 17:15 19女士们,先生们,早上好!很荣幸有机会参加此次面试。我希望今天 ... -
SSH 配置文件
2011-04-18 15:50 1341将一年前写的SSH基于配置的改成 Hibernate基于注解的 ... -
备份配置 - spring
2011-04-16 20:43 613<?xml version="1.0" ... -
Hibernate-学习笔记06-Relationship-One2One
2011-04-14 20:57 1060Hibernate真的很强大,尤其是在关系这方便,方便到只要你 ... -
Spring-学习笔记01-CrossCuttingConcern
2011-04-14 19:30 884近做Spring试验发现了个问题: 1、advice不能监控 ... -
Hibernate-学习笔记05-数据持久化的三种状态
2011-04-13 20:26 1435Hibernate 数据持久化 ... -
Hibernate-学习笔记04-数据更新方法
2011-04-13 20:02 4200试验目的: 更新数 ... -
Hibernate-学习笔记03-getCurrentSession和openSession区别
2011-04-12 19:52 1509SessionFactory得到Session的方法有两种ge ... -
Hibernate-学习笔记01
2011-04-11 15:53 1060第一个Hibernate小程序 Hiberna ... -
Interceptor的初步认识
2011-03-31 18:15 1078一个名称 : AOP(Aspect ... -
Struts2 Action中的数据填充
2011-03-31 13:53 1880开门见山 直接上代码 ... -
struts-笔记-7
2011-03-18 16:02 8718 Dynamic ActionForm ... -
struts-笔记-6
2011-03-18 16:01 9977 标签 Struts ... -
Struts-笔记-5
2011-03-18 15:57 10216.Struts 的 MVC 组件 ... -
Struts-笔记-4
2011-03-18 15:55 7744.Struts 工作原理和开发流程 4 ... -
Struts-笔记-3
2011-03-18 15:54 10813. 用 struts 开发简单的登录示例程 ... -
Struts-笔记-2
2011-03-18 15:53 8382 . 搭建 Struts 开发环境 ... -
Struts-笔记-1
2011-03-18 15:50 838******************************* ...
相关推荐
基于注解驱动的Struts_Spring_Hibernate开发 实例详解
是我自己做的springMVC+hibernate的环境,包括连接数据库查询,基于注解的方式
hibernate@注解方式配置实体类时,利用javadoc接口生成数据库表及字段的注释说明,支持oracle、sqlserver、db2、mysql数据库。因用到java\lib\tools.jar,需要将该jar放入工程lib下(或者tomcat\lib下、或加入...
车辆管理系统(struts+hibernate+spring+oracle),车辆管理系统(struts+hibernate+spring+oracle),车辆管理系统(struts+hibernate+spring+oracle),
* @GenericGenerator —— 注解声明了一个hibernate的主键生成策略。支持十三种策略。该注解有如下属性 * name 指定生成器名称 * strategy 指定具体生成器的类名(指定生成策略)。 * parameters 得到strategy指定的...
hibernate-3.4入门的简单示例,用注解的方式操作oracle数据库。源码导入可运行。 还包括hibernate-annotations-3.4.0.GA.zip、hibernate-distribution-3.3.2.GA-dist.zip、slf4j-1.5.8.zip、ojdbc14.jar
Struts2+Spring3+hibernate3全注解,操作oracle emp表的查询
hibernate@注解方式配置实体类时,利用javadoc接口生成数据库表及字段的注释说明,支持oracle、sqlserver、db2、mysql数据库。因用到java\lib\tools.jar,需要将该jar放入工程lib下(或者tomcat\lib下、或引用方式都行...
springmvc+spring+hibernate整合,全注解,应用了存储过程和拦截器,数据库为oracle数据库,内附建表语句和存储过程语句
全注解配置Spring3+SpringMVC+Hibernate4,Eclipse含jar,导入直接使用。 数据库使用Oracle,可以按照配置文件dataSource的内容建用户。 访问http://localhost/eap将调用FileManagerControl的getFileServerList方法...
1.通过google ehcache-spring-annotatios.jar自动注解方式实现整合Spring+Ehcache。 2.Action里通过struts2-spring-plugin.jar插件自动根据名字注入。 3.Ajax无刷新异步调用Struts2,返回Json数据,以用户注册为例。...
已经搭建好的ssh2架构,有自动建表功能,spring和hibernate的全注解,只要修改spring里的数据库连接密码,然后再在mysql命名一个first库,就可以用,所有表格根据类自动生成.开发方便
hibernateTools ,修改支持eclipse 逆向生成model 和xml映射。修改支持oracle 表中文注解。
可运行的SpringMVC项目,是通过springmvc注解的方式进行的,同时集成了Hibernate,数据库是Oracle,里面也有SpringMVC对文件上传、Ajax请求、自定义拦截器功能的实现,出自csdn上的linuszhu的SpringMVC经典系列。
该框架是SSH2框架搭建,Spring3+hibernate3+JPA2,全注解实现。使用oracle数据库(包中包含创建语句),数据库访问层dao使用hibernate+jpa和jdbctemplate两种方式实现。并包括log4j,filter拦截器等技术。
hibernate+spring+springMVC+maven+eclipse+mysql(oracle)
本系统使用Hibernate注解、Oracle为后台数据库、前台界面大量使用了Jquery和Ajax技术,以界面高度集成式模式,模拟实现了在线拍卖系统的功能。
整合SSH2(全注解)框架,方便初学者下载学习。内附db脚本 实例为oracle数据库、采用Struts2,Spring,Hibernate框架。
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect <prop key="hibernate.show_sql">true <prop key="hibernate.hbm2ddl.auto">update <prop key="default_schema">${jdbc....
springMVC3,hibernate3,Extjs json,spring注解,oracle,表自动生成