@Entity
@Table(name="tablename")
public class A{
private int id
private String name
private String B//添加B的引用
}
@Id
@GeneratedValue
public int getId() {
return Id
}
public void setid(int Id) {
Id = Id
}
@OneToMany(cascade=CascadeType.ALL)
public String getB(){//自动生成get、set方法}
public void setB(String B){……}
======================================
B类:
@Entity
@Table(name="tablename")
public class B{
private int id
private String name
private String A//添加B的引用,变成双向映射
}
@Id
@GeneratedValue
public int getId() {
return Id
}
public void setid(int Id) {
Id = Id
}
@ManyToOne(mappedBy="B",
cascade=CascadeType.ALL)
public String getA(){//自动生成get、set方法}
public void setA(String A){……}
我也初学,仅供参考呢
触发器方式: create trigger trg_A on A for update,delete as begin if exists(select 1 from inserted) update B set Name=(select Name from inserted) where Name=(select Name from deleted) else delete B where Name=(select Name from deleted) end go 要使用级联性更新和删除,用户可以在Alter TABLE 语句的CONSTRAINT子句中使用ON Update CASCADE 和/或 ON Delete CASCADE 关键字。注意他们都必须是应用于外键的。 级联更新和级联删除方式: Alter TABLE [dbo].[T_USERGROUP] ADD CONSTRAINT [FK_T_USERGROUP_T_ACCTTEMPLATE] FOREIGN KEY ( [ATNAME] ) REFERENCES [dbo].[T_ACCTTEMPLATE] ( [ATNAME] ) ON Update CASCADE ON Delete CASCADE欢迎分享,转载请注明来源:内存溢出
评论列表(0条)