我的问题是在退出之后,当我运行这个启动类时,我得到一个带有空表的新架构以前插入数据库的所有数据都被删除了任何人都可以建议练习来过来这个
package com.flp.fms.view;
import java.text.ParseException;
import java.util.Scanner;
import javax.persistence.*;
import com.flp.fms.dao.FilmDaoImplForDB;
public class BootClass
{
static BootClass bc=new BootClass();
static Scanner sc=new Scanner(System.in);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("hello");
EntityManager em = emf.createEntityManager();
UserInteraction ui=new UserInteraction(em);
public static void main(String args[]) throws ParseException
{
while(true)
{
System.out.println("Menu");
System.out.println("-------------");
System.out.println("1.AddFilm"+"\n"+"2.ModifyFilm"+"\n"+"3.RemoveFilm"+"\n"+"4.SearchFilm"+"\n"+"5.getAllFilm"+"\n"+"6.AddActor"+"\n"+"7.ModifyActor"+"\n"+"8.RemoveActor"+"\n"+"9.SearchActor"+"\n"+"10.getAllActor"+"\n"+"11.Exit");
System.out.println("Enter your Choice");
int choice = sc.nextInt();
if(choice==11)
{
}
bc.menuSelection(choice);
}
}
private void menuSelection(int choice) throws ParseException
{
switch(choice)
{
case 1:em.getTransaction().begin();
ui.AddFilm();
em.getTransaction().commit();
break;
case 2:ui.ModifyFilm();
break;
case 3:em.getTransaction().begin();
ui.RemoveFilm();
em.getTransaction().commit();
break;
case 4:ui.SearchFilm();
break;
case 5:ui.getAllFilm();
break;
case 6:em.getTransaction().begin();
ui.AddActor();
em.getTransaction().commit();
break;
case 7:ui.ModifyActor();
break;
case 8:em.getTransaction().begin();
ui.RemoveActor();
em.getTransaction().commit();
break;
case 9:ui.SearchActor();
break;
case 10:ui.getAllActor();
break;
default:System.out.println("Inavalid Menu Selection");
break;
case 11:System.exit(0);
break;
}
}
}
答案 0 :(得分:1)
您是否设置了hibernate.hbm2ddl.auto
属性以在hibernate属性中创建?如果是,则将其更改为验证
hibernate.hbm2ddl.auto
会自动验证或将架构DDL导出到数据库。使用create-drop,当SessionFactory显式关闭时,将删除数据库模式。
e.g。验证|更新|创建|创建降