我的 SQL Server 数据库有 8 个具有相同结构的表。 现在我想用一个 Java 类插入选定的表。
@Entity
@Table(name = "tbl_Prognosen") //here I want to put all table-Names
public class AZBNachricht { ...
这可能吗?
最佳答案
不可能完成您所描述的任务。
在实体类级别最接近代码重用的方法是使用 @MappedSuperclass
类,在其中放置所有共享列名称等,然后使用不同的表名称为每个表实现扩展该类。
@MappedSuperclass
public abstract class AbstractStructure {
@Id
@GeneratedValue;
private Integer id;
private String column1;
private String column2;
}
@Entity
@Table(name = "table1")
public class Entity1 extends AbstractStructure {
}
// ... so on
关于java - 表中的更多名称属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41980611/