我@OneToMany在父实体和子实体之间进行简单映射时遇到问题.一切正常,只有当我从集合中删除它们时才会删除子记录.
父母:
@Entity
public class Parent {
@Id
@Column(name = "ID")
private Long id;
@OneToMany(cascade = {CascadeType.ALL}, mappedBy = "parent")
private Set<Child> childs = new HashSet<Child>();
...
}
Run Code Online (Sandbox Code Playgroud)
孩子:
@Entity
public class Child {
@Id
@Column(name = "ID")
private Long id;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name="PARENTID", nullable = false)
private Parent parent;
...
}
Run Code Online (Sandbox Code Playgroud)
如果我现在从子集Set中删除和子节点,它不会从数据库中删除.我试图使child.parent引用无效,但这也无效.
实体用于Web应用程序,删除是作为Ajax请求的一部分发生的.按下保存按钮时,我没有已删除子项的列表,因此我无法隐式删除它们.
我从wsdl文件生成Java源代码.这些源不受版本控制(但是wsdl是).我们在maven中使用cxf-codegen-plugin,并生成生成的类<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>.
这在maven中运行良好.
我必须将此目录定义为Intelij Idea中的附加源目录.(target通常被排除在外).
但每次我将maven项目重新导入InteliJ Idea时(由于pom更改),我必须在Idea中手动编辑项目结构并重新定义添加源目录.
有没有什么方法可以在maven中定义这个aditional源目录,所以Idea在重新加载时选择它,或者告诉Idea不要忘记手动源directoy定义?
你如何处理由hibernate管理的java对象的对象相等性?在"hibernate in action"一书中,他们说人们应该支持商业密钥而不是代理密钥.
大多数时候,我没有业务密钥.想一想映射到一个人的地址.地址保存在一个Set中,并显示在Wicket RefreshingView(具有ReuseIfEquals策略)中.
我可以使用代理id或使用equals()和hashCode()函数中的所有字段.
问题是那些字段在生命周期中对象变化.要么是因为用户输入了一些数据,要么由于在OSIV(在视图中打开会话)过滤器内调用JPA merge()而导致id发生变化.
我对equals()和hashCode()契约的理解是那些在对象的生命周期内不应该改变的.
到目前为止我尝试了什么:
我需要的是在我认为在对象创建期间分配的ID.这里有什么选择?我不想引入一些额外的持久属性.有没有办法明确告诉JPA为对象分配ID?
问候
我正在开发一个使用Wicket作为视图层和JPA(Hibernate)作为ORM的应用程序.使用Wicket构建UI非常有趣(即使使用ajax).我的问题来自于在编辑页面上集成持久对象(使用LoadadableDetachableModel只读页面没问题).
我正在使用spring的OSIV过滤器为视图提供一个打开的会话.但是,当我在编辑页面中保留域对象(@Entity映射类)时,当我在ajax回调中访问它们的属性时,我得到了可怕的延迟加载.
我真的不想走DTO/VO的道路,因为我认为它只会使代码变得臃肿,并且需要我编写大量的样板代码.
一种想法是在视图中使用模型对象,将传入的对象与当前的hibernate会话合并,并访问所有的getter以完全初始化对象.在此之后,对象将存储在视图(seesion)中并变为分离.保存后,我会重新合并它并提交更改.
这是推荐的方式吗?有更好的解决方案吗?奇怪的是,大多数书籍/博客/ howtos完全忽略了这样的问题.
你会建议什么交易管理?现在我在服务层使用@Transaction.如果我使用其他方式访问跨hibernate会话存储数据,会如何改变?
任何指针/链接都受欢迎,因为我有点迷失在这里..
提前致谢
我在WebService中面临一个问题,详细说明:
Caused by: org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:276)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:222)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:171)
... 26 more
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1000)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1900)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1828)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:590)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
... 31 more
Run Code Online (Sandbox Code Playgroud)
当我尝试向目标服务发送请求时,需要30-60秒,并且抛出上述异常.我正在使用Tomcat 5,我想问有没有办法增加超时值?我想要访问的WSDL和WebService也在运行和可用.
我非常感谢任何帮助,
亲切的问候,P.
我在使用2个可选路径从图表中选择数据时遇到问题.假设节点A,B,C,其中A与B和C具有可选关系.
如果我查询
match (a:A) where a.xx = XX optional match (a:A)-->(b:B) return ...
Run Code Online (Sandbox Code Playgroud)
要么
match (a:A) where a.xx = XX optional match (a:A)-->(c:C) return ...
Run Code Online (Sandbox Code Playgroud)
一切都按预期工作.
如果我结合2:
match (a:A) where a.xx = XX
optional match (a:A)-->(b:B)
optional match (a:A)-->(c:C)
return ...
Run Code Online (Sandbox Code Playgroud)
然后我只得到(经过长时间的查询时间)一个未知的错误.
返回从a,b,c中选择属性,并使用限制来限制返回的数据量.是否不可能有多个可选匹配?
更新: 当我将查询更改为
match (a1:A) where a.xx = XX
optional match (a2:A)-->(b:B) where a2.uid = a1.uid
optional match (a3:A)-->(c:C) where a3.uid = a1.uid
return ...
Run Code Online (Sandbox Code Playgroud)
如果uid是唯一的索引id,则查询返回所需的结果.但它的运行速度非常慢(如果uid是索引,则为~60秒,如果uid具有唯一约束,则为〜40s)数据集不是我称之为巨大的数据集:6500,b 86和c 90000条目.
我在wicket做一个项目如何解决问题.我遇到了这样一条消息:WicketMessage:无法使用构造函数public itucs.blg361.g03.HomePage()实例化页面
根本原因:
java.lang.UnsupportedOperationException:[SQLITE_BUSY]在itucs.blg361.g03.CategoryEvents.CategoryEventCollection.getCategoryEvents(CategoryEventCollection.java:41)中锁定数据库文件(数据库已被锁定)
public List<CategoryEvent> getCategoryEvents() {
List<CategoryEvent> categoryEvents = new
LinkedList<CategoryEvent>();
try {
String query = "SELECT id, name, group_id"
+ " FROM event_category";
Statement statement = this.db.createStatement();
ResultSet result = statement.executeQuery(query);
while (result.next()) {
int id = result.getInt("id");
String name = result.getString("name");
int group_id = result.getInt("group_id");
categoryEvents.add(new CategoryEvent(id, name, group_id));
}
} catch (SQLException ex) {
throw new UnsupportedOperationException(ex.getMessage());
}
return categoryEvents;
}
Run Code Online (Sandbox Code Playgroud)
at itucs.blg361.g03.HomePage.(HomePage.java:71)
categories = categoryCollection.getCategoryEvents();
Run Code Online (Sandbox Code Playgroud)
在java.lang.reflect.Constructor.newInstance(Constructor.java:525)
我正在尝试使用 DSL 测试一些带有 spring-integration 的东西。到目前为止,这只是一个测试,流程很简单:
除了聚合器,它工作正常:
@Bean
public IntegrationFlow integrationFlow() {
return IntegrationFlows
.from(integerMessageSource(), c -> c.poller(Pollers.fixedRate(1, TimeUnit.SECONDS)))
.channel(MessageChannels.executor(Executors.newCachedThreadPool()))
.handle((GenericHandler<Integer>) (payload, headers) -> {
System.out.println("\t delaying message:" + payload + " on thread "
+ Thread.currentThread().getName());
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
System.err.println(e.getMessage());
}
return payload;
})
.handle(this::logMessage)
.aggregate(a ->
a.releaseStrategy(g -> g.size()>10)
.outputProcessor(g ->
g.getMessages()
.stream()
.map(e -> e.getPayload().toString())
.collect(Collectors.joining(",")))
)
.handle(this::logMessage)
.get();
}
Run Code Online (Sandbox Code Playgroud)
如果我省略了 .aggregate(..), 部分,则示例正在运行。
使用聚合器,我得到以下异常:
Caused by: org.springframework.beans.factory.BeanCreationException: The 'currentComponent' …Run Code Online (Sandbox Code Playgroud)