我尝试在实例条件中获取元素列表。在执行中我获得了这个例外。有什么问题?
我的数据库名称是“TransPlusBD”。 我的桌子名称是“gerant”。 但错误表明他(他)没有找到表“TransPlusDB.gerant_gerant”,但该表不存在。 通常我们必须拥有他的“TransPlusDB.gerant”。
配置代码
properties = new Properties();
properties.put("hibernate.dialect","org.hibernate.dialect.MySQLInnoDBDialect");
properties.put("hibernate.connection.driver_class","com.mysql.jdbc.Driver");
properties.put("hibernate.connection.url","jdbc:mysql://(cloud amazone aws).amazonaws.com:3306/TransPlusDB");
properties.put("hibernate.connection.username","xxx");
properties.put("hibernate.connection.password","xxxxxxxxxxxx");
properties.put("hibernate.connection.pool_size","4");
configuration = new Configuration();
configuration.setProperties(properties);
configuration.addAnnotatedClass(Administrator.class);
configuration.addAnnotatedClass(AutoGare.class);
configuration.addAnnotatedClass(Car.class);
configuration.addAnnotatedClass(City.class);
configuration.addAnnotatedClass(Company.class);
configuration.addAnnotatedClass(transplus.models.Configuration.class);
configuration.addAnnotatedClass(DateDeparture.class);
configuration.addAnnotatedClass(Departure.class);
configuration.addAnnotatedClass(HoursDeparture.class);
configuration.addAnnotatedClass(Luggage.class);
configuration.addAnnotatedClass(Manager.class);
configuration.addAnnotatedClass(Passenger.class);
configuration.addAnnotatedClass(PlanningVoyage.class);
configuration.addAnnotatedClass(Route.class);
configuration.addAnnotatedClass(Stopover.class);
configuration.addAnnotatedClass(SysAdmin.class);
configuration.addAnnotatedClass(Ticket.class);
configuration.addAnnotatedClass(TypeCar.class);
configuration.addAnnotatedClass(ModificationLuggage.class);
configuration.addAnnotatedClass(ModificationTicket.class);
configuration.addAnnotatedClass(PassageRoute.class);
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
我班级的代码
@Entity
@Table(name = "gerant")
public class Manager implements Serializable // Table Gerant
{
@Id
@GeneratedValue
@Column(name = "code_gerant")
private long code_manager;
@Column(name = "matricule_gérant",unique = true)
private String matricule_manager;
@Column(name = "nom_gerant")
private String lastName_manager;
@Column(name = "prenom_gerant")
private String firstName_manager;
@Column(name = "password_gerant",nullable = false)
private String password_manager;
@Column(name = "login_gerant",unique = true,nullable = false)
private String login_manager;
@Column(name = "poste_gerant")
private String function_manager;
@Column(name = "actif_gerant")
private boolean enabled_manager;
@Enumerated(EnumType.ORDINAL)
@Column(name = "privilege_gerant")
private Privilege privilege;
@ManyToOne
@JoinColumn(name = "code_manager", foreignKey = @ForeignKey(name = "fk_gerant_manager"))
private Administrator administrator;
@ManyToOne
@JoinColumn(name = "over_gerant", foreignKey = @ForeignKey(name = "fk_over_gerant"))
private Manager overManager;
@Expose // Annotation for Gson
@OneToMany(cascade = CascadeType.ALL,orphanRemoval = false)
private List<Manager> underManagers = new ArrayList<>();
恢复清单的代码。
public String getAllManager()
{
if(session.isOpen())
{
Transaction transaction = null;
try
{
transaction = session.beginTransaction();
transaction.begin();
Criteria criteria = session.createCriteria(Manager.class);
List list = criteria.list();
transaction.commit();
if(list != null)
{
if(!list.isEmpty())
return serializeTab(list);
}
return null;
}
catch (Exception e)
{
if(transaction != null)
transaction.rollback();
e.printStackTrace();
}
}
return null;
}
以下是引发的异常
this = {ServiceManager@3681}
transaction = {TransactionImpl@3683}
transactionCoordinator = {JdbcResourceLocalTransactionCoordinatorImpl@3979}
transactionDriverControl = {JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl@3980}
valid = false
e = {SQLGrammarException@3954} "org.hibernate.exception.SQLGrammarException: could not extract ResultSet"
sqlException = {MySQLSyntaxErrorException@3958} "com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'TransPlusDB.gerant_gerant' doesn't exist"
SQLState = "42S02"
vendorCode = 1146
next = null
detailMessage = "Table 'TransPlusDB.gerant_gerant' doesn't exist"
cause = {MySQLSyntaxErrorException@3958} "com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'TransPlusDB.gerant_gerant' doesn't exist"
stackTrace = {StackTraceElement[0]@3961}
suppressedExceptions = {Collections$UnmodifiableRandomAccessList@3962} size = 0
sql = "n/a"
帮助我请
答案 0 :(得分:0)
表var filteredBindingList = new BindingList<StudentGrade>(
_studentGrade.Where(x => x.StudentID == studentID).ToList());
dgvGrades.DataSource = filteredBindingList;
是此
gerant_gerant
您需要让Hibernate使用@OneToMany(cascade = CascadeType.ALL,orphanRemoval = false)
private List<Manager> underManagers = new ArrayList<>();
属性创建此表,或者您可以使用约束(外键,唯一键)手动创建它。
您可以使用hibernate.hbm2ddl.auto
注释指定连接表名称。
答案 1 :(得分:0)
我在配置级别添加了这行代码
properties.put("hbm2ddl.auto","validate");
然后这个代码在我的班级
@OneToMany(cascade = CascadeType.ALL,orphanRemoval = false,mappedBy = "overManager")
private List<Manager> underManager;
感谢