我正在写一个库,我使用sfl4j来处理日志.
我认为这是个好主意,只要每个机构都能提供它自己的实现,然后,我的应用程序提供的日志将被正确处理.
但我不知道是否必须提供实现作为传递依赖.
例:
如果我只提供:
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
我的lib的用户可以选择实现,但如果他只是添加我的lib而没有读取配置,它将无法工作
否则,如果我提供:
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
我的lib只在向它添加依赖项时才能正常工作,但是如果用户想要使用其他slf4j,他将不得不排除我的.
你对此有何看法?
我有一个简单的实体与OneToMany关系:
@Column(name = "TITLE")
private String _title;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "PROJECT_ID")
private Set<Device> _devices;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "PROJECT_ID")
private Set<Firm> _firms;
Run Code Online (Sandbox Code Playgroud)
而且我想在PostLoad方法中使用我的设置
@PostLoad
private void copyToProperty() {
title.set(_title);
if (_devices != null && !_devices.isEmpty())
//DO Stuff HERE
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试访问_devices时,我得到了这个异常:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1215)
at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:635)
at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:589)
at com.dooapp.jpa.Main.main(Main.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) …Run Code Online (Sandbox Code Playgroud)