问题描述
我有两个具有一对多关系的实体
孩子有一个组合键
当我尝试使用级联通过父项插入子项时
返回空异常
iam使用spring jpa,hibernate,springboot
父母
@IntRange(from = 0,to = 3)
fun getConnectionType(context: Context): Int {
var result = 0 // Returns connection type. 0: none; 1: mobile data; 2: wifi
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val capabilities =
cm.getNetworkCapabilities(cm.activeNetwork)
if (capabilities != null) {
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
result = 2
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
result = 1
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
result = 3
}
}
} else {
val activeNetwork = cm.activeNetworkInfo
if (activeNetwork != null) {
// connected to the internet
if (activeNetwork.type === ConnectivityManager.TYPE_WIFI) {
result = 2
} else if (activeNetwork.type === ConnectivityManager.TYPE_MOBILE) {
result = 1
} else if (activeNetwork.type === ConnectivityManager.TYPE_VPN) {
result = 3
}
}
}
return result
}
孩子
@Entity
@Table(name="ITEM",schema="MGITCLOTHES2020",uniqueConstraints = {@UniqueConstraint(columnNames="CODE_COMPANY"),@UniqueConstraint(columnNames="NAME")}
)
public class Item implements java.io.Serializable {
@Id
@SequenceGenerator(name = "ITEM_ID_GENERATOR",allocationSize = 1,sequenceName = "SEQ_ITEM")
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "ITEM_ID_GENERATOR")
@Column(name = "ID",unique = true,nullable = false,precision = 22,scale = 0)
private Long id;
@OnetoMany(fetch = FetchType.LAZY,mappedBy = "item",cascade = CascadeType.ALL)
private List<Itemunit> itemunits = new ArrayList<Itemunit>(0);
public Item() {
}
我正在使用Embedded ID的此复合密钥
@Entity
@Table(name = "ITEM_UNIT",schema = "MGITCLOTHES2020"
)
public class Itemunit implements java.io.Serializable {
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "unitId",column = @Column(name = "UNIT_ID",scale = 0)),@AttributeOverride(name = "itemId",column = @Column(name = "ITEM_ID",scale = 0))})
private ItemunitId id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ITEM_ID",insertable = false,updatable = false)
private Item item;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "UNIT_ID",updatable = false)
private Unit unit;
public Itemunit() {
}
错误消息是 oracle.jdbc.OracleDatabaseException:ORA-01400:?? ???? ?????? NULL((“ MGITCLOTHES2020”。“ ITEM_UNIT”。“ ITEM_ID”) 在oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:513)〜[ojdbc8-19.3.0.0.jar:19.3.0.0.0] 在oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:461)〜[ojdbc8-19.3.0.0.jar:19.3.0.0.0] 在oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1104)〜[ojdbc8-19.3.0.0.jar:19.3.0.0.0] 预先感谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)