2013-08-25 60 views
2

我正在爲我的應用程序使用Hibernate(3.0)+ Oracle DB(10g)。ORACLE:org.hibernate.ObjectNotFoundException:不存在具有給定標識符的行

我的域對象都像PluginConfig.java

@Entity 
@Table(name = "plugin_config" , schema = "test") 
@org.hibernate.annotations.Cache(usage =org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE) 
public class Config { 

private static final long serialVersionUID = -92627830L; 

/** This object's id */ 
@Id 
@GeneratedValue(strategy = GenerationType.AUTO) 
protected long id; 

@OneToOne 
@JoinColumn(name = "plugin_id") 
private Plugin plugin; 

@Column(name = "config_name") 
@NaturalId(mutable = true) 
private String name; 

@Column(name = "config_desc") 
private String description; 

另一個域對象Plugin.java

@Entity 
@Table(name = "plugin", schema = "test") 
@org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE) 
public class Plugin implements Serializable { 

private static final long serialVersionUID = 5694761325202724778L; 

/** This object's id */ 
@Id 
@GeneratedValue(strategy = GenerationType.AUTO) 
protected long id; 

@Column(name = "plugin_name") 
@NaturalId 
private String pluginName; 
@OneToOne 
@JoinColumn(name = "plugin_config_id") 
private PluginConfig pluginConfig; 

@Column(name = "plugin_desc") 
private String description; 

每當我試着通過數據庫服務方法加載插件(使用@Transactional註解,因此它會加載它的所有子項)我得到以下錯誤

org.hibernate.ObjectNotFoundEx ception:不存在具有給定標識符的行:[PluginConfig#53]

plugin_config表中實際上沒有與id = 53的行。 也沒有插件表條目plugin_config_id=53

那麼從何處挑選這些值呢? 我注意到這裏有一件事,值「53」實際上是來自plugin_config表的行號,它應該已被緩存。

見下面的圖片:

enter image description here

這是我的查詢應該尋找插件配置。但它試圖用標識符#53(行號:)而不是#95(主鍵「id」的值)進行搜索。

我在哪裏可能會出錯?

+0

查看圖片! [1]:http://i.stack.imgur.com/hVpob.png – GSG

+0

基於'plugin_config_id'的對應對象是否存在?你如何試圖在'plugin_config'表中加載實體? –

+0

你是如何生成你的表格ID的? –

回答

1

我不知道這是德最好的解決辦法,但你可以使用@NotFound批註與IGNORE命令讓Hibernate丟棄異常ADN設置pluginConfignull

@OneToOne 
@JoinColumn(name = "plugin_config_id") 
@NotFound(action = NotFoundAction.IGNORE) 
private PluginConfig pluginConfig; 
+0

可悲的是,這不是我的選擇。在這種特殊情況下,我可能已經走了,但我有一個整體應用程序,我面臨同樣的問題。我需要一些其他解決方法。 – GSG

相關問題