开发者社区> 问答> 正文

hibernate整合spring是,控制台没包任何异常,但是就是不能自动创建表 怎么回事啊?

一下是习惯的xml配置跟Java代码

web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
myshop

 <welcome-file>customer_login.jsp</welcome-file>



contextConfigLocation
classpath:config/springAnnotation-.xml



org.springframework.web.context.ContextLoaderListener



springMVC
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
classpath*:config/springAnnotation-servlet.xml

1


springMVC
/



encodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding
UTF-8


forceEncoding
true



encodingFilter
/*


openSession
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter


openSession
/*


关于hibernate的配置

<?xml version="1.0" encoding="UTF-8"?>


]>












org.hibernate.dialect.MySQLDialect
create
true










PROPAGATION_REQUIRED,-Exception
PROPAGATION_REQUIRED,-Exception
PROPAGATION_REQUIRED,-Exception
PROPAGATION_REQUIRED,-Exception
PROPAGATION_REQUIRED,-Exception
PROPAGATION_NEVER



关于spring的配置

<?xml version="1.0" encoding="UTF-8"?>
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans

   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
   http://www.springframework.org/schema/context  
   http://www.springframework.org/schema/context/spring-context.xsd  
   http://www.springframework.org/schema/mvc  
   http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">








   <property name="defaultEncoding" value="utf-8"/>
   <!-- <property name="maxUploadSize" value="10485760000"/>
   <property name="maxInMemorySize" value="40960"/>
   -->
   </bean>


Java代码实体类

package cn.zmf.entity;

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_customer")
public class Customer {

@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid",strategy="uuid")
@Column(length=36)
private String customerId;
@Column(length=32)
private String customerName;
@Column(length=32)
private String customerSex;
@Column(length=32)
private String customerAge;
@Column(length=32)
private String customerPassword1;
@Column(length=32)
private String customerPassword2;

public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCustomerSex() {
return customerSex;
}
public void setCustomerSex(String customerSex) {
this.customerSex = customerSex;
}
public String getCustomerAge() {
return customerAge;
}
public void setCustomerAge(String customerAge) {
this.customerAge = customerAge;
}
public String getCustomerPassword1() {
return customerPassword1;
}
public void setCustomerPassword1(String customerPassword1) {
this.customerPassword1 = customerPassword1;
}
public String getCustomerPassword2() {
return customerPassword2;
}
public void setCustomerPassword2(String customerPassword2) {
this.customerPassword2 = customerPassword2;
}
}

Java代码Dao

import javax.annotation.Resource;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.omg.CORBA.PRIVATE_MEMBER;
import org.springframework.stereotype.Service;

import cn.zmf.entity.Customer;

@Service(value="customerLoginDao")
public class CustomerLoginDao implements ICustomerLoginDao {

@Resource(name="sessionFactory")
private SessionFactory sessionFactory;
@Override
public void register(Customer customer) {
try {
Session session = sessionFactory.getCurrentSession();
session.save(customer);
session.flush();
} catch (Exception e) {
e.printStackTrace();
}
}

service代码

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.zmf.dao.CustomerLoginDao;
import cn.zmf.entity.Customer;

@Service(value="customerLoginService")
public class CustomerLoginService implements ICustomerLoginService {

@Resource(name="customerLoginDao")
private CustomerLoginDao customerLoginDao;
@Override
public void register(Customer customer) {
customerLoginDao.register(customer);
}

}

controller代码

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.zmf.entity.Customer;
import cn.zmf.service.CustomerLoginService;

@Controller
@RequestMapping("/customer")
public class CustomerLoginController {
@Resource(name="customerLoginService")
private CustomerLoginService customerLoginService;

@RequestMapping("/register")
public String register(Customer customer){
customerLoginService.register(customer);
return "/customerregister";
}
}

展开
收起
爵霸 2016-02-29 15:25:23 2668 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
DTS控制台一本通 立即下载

相关实验场景

更多