使用hibernate/jpa时,我无法在spring中自动创建表.
这是我的配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="naveroTest">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>xxx</class>
...
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
<property name="hibernate.connection.url" value="jdbc:hsqldb:file:/tmp/naveroTestDB"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
</properties>
</persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)
的context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:tx="http://www.springframework.org/schema/tx"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd">
<!-- For auto creation of tables -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:file:/tmp/naveroTestDB" />
<property name="username" value="sa" …Run Code Online (Sandbox Code Playgroud) 我知道使用Eclipse创建任务的两种方法; 使用任务视图或TODO注释中的注释:
//TODO: wtf? Rewrite it using constants.
int foo = 3.1 * 3;
Run Code Online (Sandbox Code Playgroud)
如果我使用第一种方式,我可以编辑任务并设置"优先级".
我可以为使用TODO注释创建的任务执行此操作吗?
我可以像在JUnit中一样检索当前运行的测试名称(使用getName()或规则)吗?
@Test
public void fooBar(){
System.out.println(magic()); //should print "fooBar"
}
Run Code Online (Sandbox Code Playgroud)
PS我不想使用一些基于堆栈跟踪的自编工具.
如何使用Java在一个HttpURLConnection中执行多个请求?
URL url = new URL("http://my.com");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
HttpURLConnection.setFollowRedirects( true );
connection.setDoOutput( true );
connection.setRequestMethod("GET");
PrintStream ps = new PrintStream( connection.getOutputStream() );
ps.print(params);
ps.close();
connection.connect();
//TODO: do next request with other url, but in same connection
Run Code Online (Sandbox Code Playgroud)
谢谢.
有没有办法使用JPA映射不可变的Value对象,如电子邮件地址?
@Immutable
@Embeddable
public final class EmailAddress {
private final String value;
public EmailAddress(String value) {
this.value = value;
}
public String getValue() {
return value;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EmailAddress that = (EmailAddress) o;
return value.equals(that.value);
}
@Override
public int hashCode() {
return value.hashCode();
}
}
Run Code Online (Sandbox Code Playgroud)
现在我在实体保存上得到例外
org.hibernate.InstantiationException: No default constructor for entity: com.domain.EmailAddress
org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:107)
org.hibernate.tuple.component.AbstractComponentTuplizer.instantiate(AbstractComponentTuplizer.java:102)
org.hibernate.type.ComponentType.instantiate(ComponentType.java:515)
org.hibernate.type.ComponentType.deepCopy(ComponentType.java:434)
org.hibernate.type.TypeHelper.deepCopy(TypeHelper.java:68)
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:302) …Run Code Online (Sandbox Code Playgroud) 我有一些不理解来自gnu clisp的动作假设,我有一些代码 (let ((x "Hi!"))(print x)).如果我从控制台执行它(比如,clisp fileName.lisp),我明白了
嗨!
但是,当我从解释器执行它时,我会看到这个文本两次.为什么?
请帮帮我.
假设我需要TreeSet使用某些域逻辑排序的元素.通过这个逻辑,一些元素的顺序并不重要,因此比较方法可以返回0,但在这种情况下我无法将它们放入TreeSet.
所以,问:我将从这样的代码中得到什么缺点:
class Foo implements Comparable<Foo>{}
new TreeSet<Foo>(new Comparator<Foo>(){
@Override
public int compare(Foo o1, Foo o2) {
int res = o1.compareTo(o2);
if(res == 0 || !o1.equals(o2)){
return o1.hashCode() - o2.hashCode();
}
return res;
}
});
Run Code Online (Sandbox Code Playgroud)
更新:
好.如果它应该永远是方法之间的一致性equals(),hashcode()并且compareTo(),作为@SPFloyd - seanizer和其他人说.如果它会更好,甚至是很好的,如果我将删除Comparable界面和移动这样的逻辑Comparator(我能做到这一点不破封装)?所以它将是:
class Foo{}
new TreeSet<Foo>(new Comparator<Foo>(){
@Override
public int compare(Foo o1, Foo o2) {
//some logic start
if(strictliBigger(o1, o2)){ return 1;}
if(strictliBigger(o2, o1)){ return -1;}
//some logic …Run Code Online (Sandbox Code Playgroud) 我想在React组件中使用bootstrap切换.但是,会显示常规复选框而不是样式元素.怎么解决?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap core CSS --> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
<script src="https://fb.me/react-0.13.1.js"></script>
<script src="https://fb.me/JSXTransformer-0.13.1.js"></script>
<script type="text/jsx">
var WordCheckBox = React.createClass({
render: function() {
return (
<div className="checkbox">
<label>
<input type="checkbox" data-toggle="toggle" data-on="On" data-off="Off" />
option1
</label>
</div>
);
}
});
React.render(
<WordCheckBox />,
document.getElementById('content')
);
</script>
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.0/css/bootstrap-toggle.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.0/js/bootstrap-toggle.min.js"></script>
</head>
<body>
<!--doesn't work. checkbox instead of toogle shown-->
<div …Run Code Online (Sandbox Code Playgroud) 我想创建构造函数,它将采用一个或多个整数并将其作为ImmutableList保存到字段中.根据Bloch的第42项"使用varargs传递一个或多个论点的正确方法",我创建了smt
class Foo{
private final ImmutableList<Integer> bar;
public Foo(Integer first, Integer... other) {
this.bar = ImmutableList.<Integer>builder()
.add(first)
.addAll(Arrays.asList(other))
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
为什么构建器不会自动获得通用?而且,因为它闻起来.我怎么能改写它?
UPD qustion泛型解决.任何有关重构的建议都非常有用.