hibernate 从数据库生成对象
- 作者: 温凉盏
- 来源: 51数据库
- 2021-01-17
将你的链接数据库的地方改成mysql的,然后使用LocalSessionFactoryBean通过映射文件生成数据库表。(注:要在数据库中建个你配置文件中写的数据库名的数据库)下面是生成例子。研究下吧,不明白的地方可以hi我!
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
public class CreateTable {
public static void main(String[] args) {
BeanFactory bf = new ClassPathXmlApplicationContext("applicationContext-*.xml");
LocalSessionFactoryBean lsfb = (LocalSessionFactoryBean) bf.getBean("&sessionFactory");
lsfb.dropDatabaseSchema();
lsfb.createDatabaseSchema();
}
}
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
public class CreateTable {
public static void main(String[] args) {
BeanFactory bf = new ClassPathXmlApplicationContext("applicationContext-*.xml");
LocalSessionFactoryBean lsfb = (LocalSessionFactoryBean) bf.getBean("&sessionFactory");
lsfb.dropDatabaseSchema();
lsfb.createDatabaseSchema();
}
}
推荐阅读
