@Column(name="DateOfBirth")
private Date dateOfBirth;
Run Code Online (Sandbox Code Playgroud)
我特别需要上面的代码来创建一个名为"DateOfBirth"的列,而不是Hibernate给我一个名为date_of_birth的列.我怎么能改变这个?是否有web.xml属性?我遇到了DefaultNamingStrategy和ImprovedNamingStrategy,但不知道如何指定其中一个.
我想做这样的事情:
@Entity public class Bar {
@Id @GeneratedValue long id;
List<String> Foos
}
Run Code Online (Sandbox Code Playgroud)
并将Foos坚持在这样的表格中:
foo_bars (
bar_id int,
foo varchar(64)
);
Run Code Online (Sandbox Code Playgroud)
更新:
我知道如何映射其他实体,但在许多情况下它是过度的.如果没有创建另一个实体或最终在某些blob列中的所有内容,看起来我建议的是不可能的.
我有4个持久化类,它们都具有相同的字段(确切地说),它们之间唯一的区别是1)类名,2)表名和3)数据.我知道这对某些人来说可能有点奇怪,但相信我有一个很好的理由我不会进入这里.
现在,我正在使用hibernate注释来配置我的类,它应该像这样工作:
@Entity
@Table(name = "store")
public class Store
{
@Id
@Column(name = "unique_id")
protected String id;
@Column
protected String category;
...
}
Run Code Online (Sandbox Code Playgroud)
..这确实有效,对于一个单独的类,但是有很多字段要映射,我想在所有四个相似的类中一次性完成所有这些,即:
public class StoreBase
{
@Id
@Column(name = "unique_id")
protected String id;
@Column
protected String category;
...
}
@Entity
@Table(name = "store1")
public class Store1 extends StoreBase
{}
@Entity
@Table(name = "store2")
public class Store2 extends StoreBase
{}
@Entity
@Table(name = "store3")
public class Store3 extends StoreBase
{}
@Entity
@Table(name = "store4")
public class Store4 extends StoreBase …Run Code Online (Sandbox Code Playgroud) 根据Java Annotation API:
RetentionPolicy.CLASS注释将由编译器记录在类文件中,但在运行时不需要由VM保留.
RetentionPolicy.RUNTIME注释将由编译器记录在类文件中,并在运行时由VM保留,因此可以反射性地读取它们.
我正在寻找"CLASS"保留政策的样本.当我们需要使用此策略而不是RUNTIME策略时.
我想根据以下链接中的示例进行一些注释处理:http://www.zdnetasia.com/writing-and-processing-custom-annotations-part-3-39362483.htm.
但是,我想在我的Android项目中实现这个,似乎我不能使用android平台的包.我是否需要添加外部罐子或者是否有我遗漏的东西?
谢谢.
我正在使用AndroidTestCase进行一些单元测试,并且想知道,如果可以使用ignore-annotation,我已经读过junit4了吗?只是使用注释会产生错误,也许,有一些特别值得关注的东西?
提前谢谢,马库斯
在Spring 3.1.1中是否可以使用Java注释配置视图解析器?
我完成了使用Java注释的所有配置,但我被卡在视图解析器中.
package com;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import javax.sql.DataSource;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import com.*;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
@ComponentScan("com")
public class AppConfig
{
{
//Other bean declarations
}
@Bean
public UrlBasedViewResolver urlBasedViewResolver()
{
UrlBasedViewResolver res = new InternalResourceViewResolver();
res.setViewClass(JstlView.class);
res.setPrefix("/WEB-INF/");
res.setSuffix(".jsp");
return res;
}
}
Run Code Online (Sandbox Code Playgroud)
我使用此代码并运行应用程序,但它没有返回适当的视图.但是,如果我在文件中配置了一个viewresolverapp-servlet.xml,它可以正常工作.
我已经阅读了一些相关的问题,但它们与我的问题并不完全相同.
我正在使用JPA + Hibernate + Spring,我想做一些我不确定是否可以使用config的东西.
我的域类具有或多或少的复杂关系.有许多元素与一个元素相关(如果它是一个树,许多元素是一个元素的儿子).
就像是:
@Entity
class Foo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne
@JoinColumn(name = "PARENT_ID")
private Foo parentNode;
...
}
Run Code Online (Sandbox Code Playgroud)
Wich会得到一张表:
Foo id parent_id
1
2 1
3 1
Run Code Online (Sandbox Code Playgroud)
当我与ID = 1删除行欲删除与ID = 2和id = 3行(它可以是递归的,与PARENT_ID = 2和PARENT_ID = 3的元件将被删除以及).
对于某些限制,我只能在父子方面与parent_id引用建立关系.
我的问题是:是否可以使用JPA或Hibernate配置执行此操作,还是需要执行一些递归功能来删除所有子项和所有父项?
我尝试过:
@OneToMany(name = "PARENT_ID", cascade = CascadeType.REMOVE)
Run Code Online (Sandbox Code Playgroud)
我读过可能使用Hibernate注释.
如果有人能给我一些线索,我就失去了这一点.
是否可以这样做:
@Entity
class Foo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne
@JoinColumn(name="PARENT_ID")
private Foo parentNode;
@OneToMany(fetch = FetchType.LAZY, …Run Code Online (Sandbox Code Playgroud) 我试图让spring cloud与使用自动配置的消息一起工作.
我的属性文件包含:
cloud.aws.credentials.accessKey=xxxxxxxxxx
cloud.aws.credentials.secretKey=xxxxxxxxxx
cloud.aws.region.static=us-west-2
Run Code Online (Sandbox Code Playgroud)
我的Configuration类如下:
@EnableSqs
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
我的听众课程:
@RestController公共类OrderListener {
@RestController
public class OrderListener {
@MessageMapping("orderQueue")
public void orderListener(Order order){
System.out.println("Order Name " + order.getName());
System.out.println("Order Url" + order.getUrl());
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行这个.我收到以下错误:
org.springframework.context.ApplicationContextException: Failed to start bean 'simpleMessageListenerContainer'; nested exception is org.springframework.messaging.core.DestinationResolutionException: The specified queue does not exist for this wsdl version. (Service: AmazonSQS; Status Code: 400; Error Code: AWS.SimpleQueueService.NonExistentQueue; Request …Run Code Online (Sandbox Code Playgroud) spring annotations amazon-sqs amazon-web-services spring-cloud
在Python 3.6中,新的变量注释在该语言中引入.
但是,当一个类型不存在时,可能会发生两种不同的事情:
>>> def test():
... a: something = 0
...
>>> test()
>>>
>>> a: something = 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'something' is not defined
Run Code Online (Sandbox Code Playgroud)
为什么不存在的类型处理行为不同?它不会潜在地导致人们忽略函数中未定义的类型吗?
笔记
尝试使用Python 3.6 RC1和RC2 - 相同的行为.
PyCharm something在函数内部和外部都突出显示为"未解析的引用".
annotations ×10
java ×5
hibernate ×4
jpa ×3
spring ×3
android ×2
spring-mvc ×2
amazon-sqs ×1
python ×1
python-3.6 ×1
python-3.x ×1
spring-cloud ×1
unit-testing ×1