是有什么区别@OnDelete(action=OnDeleteAction.CASCADE)和cascade=CascadeType.REMOVE
我在这里读到:在 JPA2
中是否有等效的 OnDelete 注释,@OnDelete(action=OnDeleteAction.CASCADE)级联将由 DB 处理,而cascade=CascadeType.REMOVE级联将由 ORM(休眠)处理。
您能解释一下 Hibernate 处理与 DB 处理之间的区别吗?它是如何“由数据库”完成的?
另外,我想知道我为什么要关心差异。我的意思是,我为什么要选择一种态度而不是另一种态度。
最后一个问题是,查看OnDelete javadoc我想知道为什么它没有说明是什么以及为什么我应该使用它(顺便说一句,继承路径在哪里?)。那么这些要点在哪里记录?
我试图了解BeanPropertyBindingResult以下代码中的内容。不幸的是,javadoc毫无用处。
请看下面的代码:
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(item, "item");
validator.validate(item, errors);
Run Code Online (Sandbox Code Playgroud)
我的问题是:
据我所知,BeanPropertyBindingResult基本上是一种Map可以包含键/值对(字段名,错误文本)的。这是正确的,还是事实更加复杂?
当我创建一个new时BeanPropertyBindingResult,为什么需要为我要验证的对象提供它(作为构造函数的第一个参数)?据我所见,在上面的第二行中,validator.validate(item, errors);验证器还是会获得对象..那么为什么要两次呢?
Javadoc讲述了构造函数的第二个参数:
objectName-目标对象的名称
是的,但是为什么我需要这个名字?我应该/可以做什么...?
我在Spring的XML配置文件之一中有以下代码:
<mvc:annotation-driven conversion-service="conversionService" />
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<list>
<bean class="org.springframework.binding.convert.converters.StringToDate">
<property name="pattern" value="yyyy-MM-dd" />
</bean>
</list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
但是我在部署期间遇到了以下异常(在JBoss上):
java.lang.IllegalArgumentException:每个转换器对象必须实现Converter,ConverterFactory或GenericConverter接口之一
知道为什么吗?据我所见,org.springframework.binding.convert.converters.StringToDate是一个实现Converter.
更新:
刚刚找到这个答案,这表明混合Converters和PropertyEditors可能会导致问题.我确实参与了我的应用程序使用PropertyEditors,但据我所知,文档没有讨论混合两个系统的任何问题.
堆栈跟踪:
Caused by: java.lang.IllegalArgumentException: Each converter object must implement one of the Converter, ConverterFactory, or GenericConverter interfaces
at org.springframework.core.convert.support.ConversionServiceFactory.registerConverters(ConversionServiceFactory.java:106)
at org.springframework.context.support.ConversionServiceFactoryBean.afterPropertiesSet(ConversionServiceFactoryBean.java:56)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 146 more
Run Code Online (Sandbox Code Playgroud)
更新2:
我改变了我的xml:
<mvc:annotation-driven conversion-service="conversionService" />
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<bean …Run Code Online (Sandbox Code Playgroud) 我从子类调用超类'受保护的方法.为什么这种方法"不可见"?
我一直在读一些职位如这一个,这似乎违背了以下内容:
超级课程:
package com.first;
public class Base
{
protected void sayHello()
{
System.out.println("hi!");
}
}
Run Code Online (Sandbox Code Playgroud)
子类:
package com.second;
import com.first.Base;
public class BaseChild extends Base
{
Base base = new Base();
@Override
protected void sayHello()
{
super.sayHello(); //OK :)
base.sayHello(); //Hmmm... "The method sayHello() from the type Base is not visible" ?!?
}
}
Run Code Online (Sandbox Code Playgroud) 为什么树排序 的平均案例时间复杂度是O(n log n)?
来自维基百科:
向二叉搜索树添加一项平均是一个 O(log n) 过程(以大 O 表示法),因此添加 n 个项目是一个 O(n log n) 过程
但是我们不会每次都将一个项目添加到由 n 个项目组成的树中。我们从一棵空树开始,逐渐增加树的大小。
所以看起来更像
log1 + log2 + ... + logn = log (1*2*...*n) = log n!
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
algorithm tree binary-tree time-complexity binary-search-tree
关于Scala类层次结构的问题:
在IDE的IntelliJ,我要找的实施Any和AnyRef,但它们不存在.他们在哪里定义,我怎么能看到他们的代码?
我在"Scala编程"中阅读了以下内容
==不直接调用equals的唯一情况是Java的盒装数字类,例如Integer或Long.在Java中,即使原始值1 == 1L,新的Integer(1)也不等于新的Long(1).由于Scala是一种比Java更常规的语言,因此有必要通过对这些类特殊地设置==方法来纠正这种差异.
嗯......但不是==最终的?他们是如何为Java的数字类做出特殊情况的?
我必须在这里遗漏一些东西......我有以下代码和输出.你能看出为什么Category categoryToBeDeleted没有从每本书的类别集中删除result?
谢谢!!
码:
List<Book> result = ... //get list from database
final Category categoryToBeDeleted = ... //get category from database
System.out.println("categoryToBeDeleted id: " + categoryToBeDeleted.getId() + " name: " + categoryToBeDeleted.getName());
for (Book book : result) {
System.out.println("before remove :");
for (Category category : book.getCategories()) {
System.out.println("category id: " + category.getId() + " name: " + category.getName() + " equals: " + category.equals(categoryToBeDeleted));
}
System.out.println("-----------------------");
book.getCategories().remove(categoryToBeDeleted);
System.out.println("after remove :");
for (Category category : book.getCategories()) { …Run Code Online (Sandbox Code Playgroud) 我在调试模式下启动了JBoss,我的项目由Maven构建,我使用Eclipse,唯一的断点在我的代码中.但是当我运行应用程序时,它会停在一个窗口上,其名称为我将断点放入的类,但它只显示"未找到源".
在我的情况下它应该是什么意思,我怎么能克服这个?
我不是Eclipse调试方面的专家,所以我希望得到彻底的解释!
我有一个Spring-Batch作业,我从Spring MVC控制器启动.控制器从用户获取上载文件,作业应该处理文件:
@RequestMapping(value = "/upload")
public ModelAndView uploadInventory(UploadFile uploadFile, BindingResult bindingResult) {
// code for saving the uploaded file to disk goes here...
// now I want to launch the job of reading the file line by line and saving it to the database,
// but I want to launch this job in a new thread, not in the HTTP request thread,
// since I so not want the user to wait until the job ends.
jobLauncher.run(
jobRegistry.getJob(JOB_NAME),
new JobParametersBuilder().addString("targetDirectory", …Run Code Online (Sandbox Code Playgroud) 在一个名为my-projecteclipse 的maven项目中,eclipse一直在告诉我
声明的包"com.myself"与预期的包"main.java.com.myself"不匹配
虽然我在项目的构建路径中验证了,但我有一个条目:
my-project/src/main/java
Included: **/*.java
Excluded: (None)
Native library location: (None)
Ignore optional compile problems: No
Run Code Online (Sandbox Code Playgroud)
那可能是什么问题呢?
解决问题的最简单方法是什么?
我怀疑eclipse设置文件有问题,因为在将项目导入工作区并将其转换为maven项目之后,我不得不手动更改文件夹结构以获得maven web项目的常规文件夹结构.但可能是在这些变化期间,日食无法正确理解某些东西.
此外,maven能够构建我的项目(从eclipse以及命令行).
我刚刚从eclipse中获得了那些编译错误.
PS我已经尝试了项目>干净,但它没有帮助.
java ×5
spring ×3
eclipse ×2
spring-mvc ×2
algorithm ×1
annotations ×1
binary-tree ×1
breakpoints ×1
buildpath ×1
collections ×1
database ×1
debugging ×1
exception ×1
hibernate ×1
jboss ×1
jpa ×1
maven ×1
protected ×1
scala ×1
spring-batch ×1
tree ×1
validation ×1
visibility ×1