package com.book.model;
// Generated 2015-11-2 9:07:06 by Hibernate Tools 4.0.0.Final
import java.util.Date;
/**
* CommentsId generated by hbm2java
*/
public class CommentsPk implements java.io.Serializable {
private Book book;
private User user;
private Date commentsDate;
public CommentsPk() {
}
public CommentsPk(Book book, User user, Date commentsDate) {
this.book = book;
this.user = user;
this.commentsDate = commentsDate;
}
public Book getBook() {
return this.book;
}
public void setBook(Book book) {
this.book = book;
}
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user = user;
}
public Date getCommentsDate() {
return this.commentsDate;
}
public void setCommentsDate(Date commentsDate) {
this.commentsDate = commentsDate;
}
public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof CommentsPk))
return false;
CommentsPk castOther = (CommentsPk) other;
return ((this.getBook() == castOther.getBook()) || (this.getBook() != null && castOther.getBook() != null
&& this.getBook().equals(castOther.getBook())))
&& ((this.getUser() == castOther.getUser()) || (this.getUser() != null && castOther.getUser() != null
&& this.getUser().equals(castOther.getUser())))
&& ((this.getCommentsDate() == castOther.getCommentsDate())
|| (this.getCommentsDate() != null && castOther.getCommentsDate() != null
&& this.getCommentsDate().equals(castOther.getCommentsDate())));
}
public int hashCode() {
int result = 17;
result = 37 * result + (getBook() == null ? 0 : this.getBook().hashCode());
result = 37 * result + (getUser() == null ? 0 : this.getUser().hashCode());
result = 37 * result + (getCommentsDate() == null ? 0 : this.getCommentsDate().hashCode());
return result;
}
}
package com.book.model;
// Generated 2015-10-30 14:56:21 by Hibernate Tools 4.0.0.Final
import java.sql.Date;
/**
* Comments generated by hbm2java
*/
public class Comments implements java.io.Serializable {
private String content;
private String pic;
private Integer client;
private CommentsPk id;
public Comments()
{
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getPic() {
return pic;
}
public void setPic(String pic) {
this.pic = pic;
}
public Integer getClient() {
return client;
}
public void setClient(Integer client) {
this.client = client;
}
public CommentsPk getId() {
return id;
}
public void setId(CommentsPk id) {
this.id = id;
}
public Comments(String content, String pic, Integer client, CommentsPk id) {
super();
this.content = content;
this.pic = pic;
this.client = client;
this.id = id;
}
}
<?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">
<!-- Generated 2015-10-30 14:56:21 by Hibernate Tools 4.0.0.Final -->
<hibernate-mapping>
<class name="com.book.model.Comments" table="comments" catalog="bookstore">
<composite-id name="id" class="com.book.model.CommentsPk">
<key-many-to-one name="book" class="com.book.model.Book">
<column name="BookID" />
</key-many-to-one>
<key-many-to-one name="user" class="com.book.model.User">
<column name="UserID" />
</key-many-to-one>
<key-property name="commentsDate" type="timestamp">
<column name="CommentsDate" length="19" />
</key-property>
</composite-id>
<property name="content" type="string">
<column name="Content" length="65535" />
</property>
<property name="pic" type="string">
<column name="Pic" length="65535" />
</property>
<property name="client" type="java.lang.Integer">
<column name="Client" />
</property>
</class>
</hibernate-mapping>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 事务的传播特性 -->
<tx:advice id="txadvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<!--hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到-->
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<?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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!-- 启用spring注解支持 -->
<context:annotation-config />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://127.0.0.1/bookstore?useUnicode=true&characterEncoding=UTF-8" />
<property name="username" value="root" />
<property name="password" value="yangyang" />
</bean>
<!-- 可追加配置二级缓存 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
<property name="dataSource" ref="dataSource"/>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:config</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.hbm2ddl.auto">update</prop>
<prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>
<prop key="current_session_context_class">thread</prop>
</props>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 事务的传播特性 -->
<tx:advice id="txadvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<!--hibernate4必须配置为开启事务 否则 getCurrentSession()获取不到-->
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 那些类那些方法使用事务 -->
<aop:config>
<!-- 只对业务逻辑层实施事务 -->
<aop:pointcut id="allManagerMethod"
expression="execution(* com.book.test.*.*(..))" />
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txadvice" />
</aop:config>
<bean name="basedao" class="com.book.dao.impl.AdressDao" />
<bean name="orderdao" class="com.book.dao.impl.OrderDao" />
</beans>
<servlet> <servlet-name>test</servlet-name> <servlet-class>com.book.test.Test</servlet-class> </servlet> <servlet-mapping> <servlet-name>test</servlet-name> <url-pattern>/index</url-pattern> </servlet-mapping>
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
BeanFactory factor = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext());
OrderDao dao= factor.getBean(OrderDao.class);
Object[] list= dao.get(1).getOrderitems().toArray();
System.out.println(((Orderitem)list[0]).getOrdercount());
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有