我在Tomcat 7中部署了一个webapp.我在洞穴中配置了我的数据库池,如下所示.
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Resource type="javax.sql.DataSource"
name="jdbc/TEST"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/testdb?zeroDateTimeBehavior=convertToNull"
username="test"
password="test"
initialSize="10"
maxActive="100"
maxIdle="50"
minIdle="10"/>
Run Code Online (Sandbox Code Playgroud)
这种配置工作正常.但是我想配置我的数据库池,以便在数据库服务器停机一段时间后自动重新连接数据数据库服务器并重新启动.
我正在使用 Oracle 数据库。我需要通过 jpa 存储库运行更新查询。这是我尝试执行的查询。
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Modifying
@Query(
value = "UPDATE transactionlog SET transactionstatus= :ps,startedat = CURRENT_TIMESTAMP, readytoprocessat= (CURRENT_TIMESTAMP+ interval ':to' second) WHERE logid IN (:li) ",
nativeQuery = true)
public Integer reserve(@Param("ps") short processingStatus, @Param("li") List<Integer> logIdList, @Param("to") int timeOut);
Run Code Online (Sandbox Code Playgroud)
但这个例外
org.springframework.dao.InvalidDataAccessApiUsageException: Parameter with that name [to] did not exist; nested exception is java.lang.IllegalArgumentException: Parameter with that name [to] did not exist
Run Code Online (Sandbox Code Playgroud)
但如果我按如下方式更改此方法,它就可以正常工作。
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Modifying
@Query(
value = "UPDATE transactionlog SET transactionstatus= :ps,startedat = CURRENT_TIMESTAMP, …
Run Code Online (Sandbox Code Playgroud) 嗨,我已经通过以下方式扩展了JpaRepository接口。
public interface StudentRepository extends JpaRepository<Student,Integer>
{
@Query(value= "SELECT s.id FROM student as s where s.createdat > ADDDATE(CURRENT_DATE, :maxage ", nativeQuery = true )
public List<Integer> findWaitingStudentIds(@Param("maxage")int maxAge);
}
Run Code Online (Sandbox Code Playgroud)
这是Entity
课程。
@Entity(name="student ")
public class Student implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(unique=true, nullable=false)
private Integer id;
@Temporal(TemporalType.TIMESTAMP)
@Column(updatable = false,insertable = false)
private Date createdat;
}
Run Code Online (Sandbox Code Playgroud)
我想为“列表findWaitingStudentIds”方法添加缓存。我该如何实现?
我在java中面临对象克隆的问题.
public class TestClass {
private int count;
private List<Integer> list;
public final int getCount() {
return count;
}
public final void setCount(int count) {
this.count = count;
}
public final List<Integer> getList() {
return list;
}
public final void setList(List<Integer> list) {
this.list = list;
}
}
public class Main {
public static void main(String[] args) {
TestClass obj = new TestClass();
obj.setCount(5);
List<Integer> temp = new ArrayList<Integer>();
temp.add(1);
temp.add(2);
obj.setList(temp);
TestClass newObj= obj;
System.out.println(newObj.getList().size());
obj.getList().add(3);
System.out.println(newObj.getList().size());
}
} …
Run Code Online (Sandbox Code Playgroud) 支持Savepoints的mysql驱动版本是什么。目前我正在使用 mysql-connector-java-5.1.18。