我不能用REmover类直接擦除代码对象...它给了我一个错误...但是当我第一次用我的代码删除连接的注释时,然后删除已经完成的代码...是否有其他方法可以自动删除代码和代码对象的注释?关于...
警告:SQL错误:0,SQLSTATE:23503 2013年6月24日2:25:51 PM org.hibernate.engine.jdbc.spi.sqlExceptionHelper logExceptions错误:错误:表“code”上的更新或删除违反了表“comments”上的外键约束“FK_EVS9QDYT93MS7UVL3UD2NWY71”详细信息:仍然从表“comments”引用key(codeid)=(14)。在org.hibernate.exception.constraintViolationException:在org.hibernate.exception.internal.sqlstateConversionDelegate.convert(sqlstateConversionDelegate.java:129)在org.hibernate.exception.internal.standardsqlExceptionConverter.convert(standardsqlExceptionConverter.convert(standardsqlExceptionConverter.java:49)在
@Entity
public class Userdetails{
@Id
@GeneratedValue
private long userid;
@Column(nullable = false, unique = true)
private String username;
private String password;
private String fname;
private String lname;
private String email;
@OneToMany(targetEntity=Code.class, mappedBy="userdetails")
private List<Code> codes;
@OneToMany(targetEntity=Messages.class, mappedBy="SMS")
private List<Messages> messages;
public List<Messages> getMessages() {
return messages;
}
public void setMessages(List<Messages> messages) {
this.messages = messages;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public List<Code> getCodes() {
return codes;
}
public void setCodes(List<Code> codes) {
this.codes = codes;
}
public Userdetails(String username, String password, String fname, String lname, String email) {
super();
this.username = username;
this.password = password;
this.fname = fname;
this.lname = lname;
this.email = email;
}
public Userdetails() {
super();
}
public static boolean updateUserDetails(Object current) {
return UserDBHandler.updateObject(current);
}
public static boolean setUserDetails(Userdetails user) {
return UserDBHandler.saveObject(user);
}
public static Userdetails getUserDetails(String username, String password) {
return UserDBHandler.loadUser(username, password);
}
public static boolean isUser(String username,String passw0rd) {
return UserDBHandler.isUser(username,passw0rd);
}
public static boolean LogoutUser() {
return UserDBHandler.LogoutUser();
}
}
package UsersProperty;
@Entity
public class Code {
@Id
@GeneratedValue
private int codeId;
private int Rating;
private int NORaters;
@Column(nullable = false, unique = true)
private String fileName;
private String OwnerName;
private String PrjName;
private String CodeLang;
private String Tags;
private String Tags2;
@ManyToOne()
@JoinColumn(name="userid")
private Userdetails userdetails;
@OneToMany(targetEntity=Comments.class, mappedBy="targetCode")
private List<Comments> cm;
public int getCodeId() {
return codeId;
}
public void setCodeId(int codeId) {
this.codeId = codeId;
}
public int getNORaters() {
return NORaters;
}
public void setNORaters(int nORaters) {
NORaters = nORaters;
}
public int getRating() {
return Rating;
}
public void setRating(int rating) {
Rating = rating;
}
public List<Comments> getCm() {
return cm;
}
public void setCm(List<Comments> cm) {
this.cm = cm;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getOwnerName() {
return OwnerName;
}
public void setOwnerName(String ownerName) {
OwnerName = ownerName;
}
public String getPrjName() {
return PrjName;
}
public void setPrjName(String prjName) {
PrjName = prjName;
}
public String getCodeLang() {
return CodeLang;
}
public void setCodeLang(String codeLang) {
CodeLang = codeLang;
}
public String getTags() {
return Tags;
}
public void setTags(String tags) {
Tags = tags;
}
public String getTags2() {
return Tags2;
}
public void setTags2(String tags2) {
Tags2 = tags2;
}
public Userdetails getUserdetails() {
return userdetails;
}
public void setUserdetails(Userdetails userdetails) {
this.userdetails = userdetails;
}
public Code(String fileName, String ownerName, String prjName,String Lang,String tAgs,String tAgs2) {
super();
this.fileName = fileName;
OwnerName = ownerName;
PrjName = prjName;
Tags=tAgs;
Tags2=tAgs2;
CodeLang = Lang;
}
public Code() {
super();
}
public static void CodeSearch(String TAGS){
SpecificCodeSearchDBHandler.searchCodeTags(TAGS);
}
public static Code LoadCode(String Path){
return CodePathLoaderDBHandler.loadCode(Path);
}
public static String FNameExtractor(String FilePath){
String Fname = null;
@SuppressWarnings("resource")
Scanner Reader = new Scanner(FilePath);
Reader.useDelimiter("/");
while(Reader.hasNext())
Fname = Reader.next();
return Fname;
}
}
package UsersProperty;
@Entity
public class Comments {
@Id
@GeneratedValue
private int cmId;
private String Cm;
private String Cmplacer;
@ManyToOne()
@JoinColumn(name="codeId")
private Code targetCode;
public Comments() {
}
public String getCm() {
return Cm;
}
public void setCm(String cm) {
Cm = cm;
}
public String getCmplacer() {
return Cmplacer;
}
public void setCmplacer(String cmplacer) {
Cmplacer = cmplacer;
}
public Code getTargetCode() {
return targetCode;
}
public void setTargetCode(Code targetCode) {
this.targetCode = targetCode;
}
public Comments(String cm, String cmplacer) {
super();
Cm = cm;
Cmplacer = cmplacer;
}
}
public class REmover {
private static Session scss;
private static SessionFactory sfactory;
static {
Configuration cfg = new Configuration();
cfg.addAnnotatedClass(Userdetails.class);
cfg.addAnnotatedClass(Code.class);
cfg.addAnnotatedClass(Messages.class);
cfg.addAnnotatedClass(Comments.class);
cfg.configure();
new SchemaExport(cfg);
sfactory = cfg.buildSessionFactory();
}
public static boolean removeCode(Object object) {
try {
scss = sfactory.openSession();
scss.beginTransaction();
scss.delete(object);
scss.getTransaction().commit();
return true;
} catch (Exception e) {
e.printStackTrace();
scss.getTransaction().rollback();
}
return false;
}
尝试向@OneTomany添加适当的级联操作,例如。
@OneToMany(targetEntity=Comments.class, mappedBy="targetCode", cascade=CascadeType.REMOVE)
看看这个API:http://docs.oracle.com/javaee/6/api/javax/persistence/onetomany.html#cascade()
和:
我正在尝试删除hibernate中的子实体,但遇到以下异常: 这些是我的实体: @table(name=“Customer”)公共类Customer{ @OneTomany(Cascade=CascadeType.All,MappedBy=“CustomerID”,OphanRemoval=True)私有集QuoteConfig; 这是我想要移除的部分 我的问题是如何删除子实体QuoteConfi
我有一个瓷砖面板的网格,其中对象(动物)随机放置在其上,作为图像。在它们实际移动之前,我需要找到一种方法来检查该特定单元旁边的四个插槽/单元(北、南、东、西),看看其中是否有食物来源,如果是,请移动到该单元。如果为false,请尝试下一个方向,如果全部为false,请随机移动。 目前,它们只是随意移动,如果幸运的是细胞上有食物来源,它们就会吃东西。这是我目前拥有的,确实有效 对于“吃”部分,有一个
我有两个表1)krs_question_bank 2)krs_options 而我正在调用Session.Save(问题)。生成了Hibernate查询,但..我有以下错误。有什么办法可以解决这个错误吗?
问题内容: 如何通过匹配对象属性从数组中删除对象? 请只使用本机JavaScript。 我在使用接头时遇到麻烦,因为每次删除的长度都会减少。使用克隆并在原始索引上进行拼接仍然会给您带来长度减少的问题。 问题答案: 我以为你用过这样的东西? 修复bug所需要做的就是在下一次减少,然后(也可以选择向后循环): 为了避免线性时间删除,可以编写要 保留 在数组上的数组元素: 为了避免在现代运行时中进行线性
问题内容: 我对级联=“删除”的工作方式感到困惑。我在“城市”映射文件中以以下方式定义了映射: 类客户具有类城市的外键。 因此,当我运行时: 是否还应该删除所有客户端,还是必须以某种方式处理它?我是否将查询作为方法参数正确传递给会话的delete()方法?谢谢你的帮助。最好的问候,混蛋。 问题答案: 我对cascade =“ delete”的工作方式有些困惑(…) 级联操作意味着,如果您是父母,则
我正在尝试编写一个代码,从ArrayList的实例中移除某些对象。 体系结构: null null 代码: