- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Hibernate 和 HSQLDB。我试图将教程改编为更当前的版本,所以可能存在问题。当我使用 JUnit 运行单元测试时会发生这种情况。
我将 HSQLDB 2.3.2 与 Hibernate (JPA) 4.3.5 一起使用。
我得到的错误是这样的:
16:40:16,802 DEBUG SQL:109 - select device0_.DEVICE_ID as DEVICE_I1_0_, device0_.DEVICE_FIRMWARE_VERSION as DEVICE_F2_0_, device0_.DEVICE_IMAGE as DEVICE_I3_0_ from DEVICES device0_ limit ? 16:40:16,802 DEBUG SQL:109 - select device0_.DEVICE_ID as DEVICE_I1_0_, device0_.DEVICE_FIRMWARE_VERSION as DEVICE_F2_0_, device0_.DEVICE_IMAGE as DEVICE_I3_0_ from DEVICES device0_ limit ? 16:40:16,802 DEBUG SQL:109 - select device0_.DEVICE_ID as DEVICE_I1_0_, device0_.DEVICE_FIRMWARE_VERSION as DEVICE_F2_0_, device0_.DEVICE_IMAGE as DEVICE_I3_0_ from DEVICES device0_ limit ? 16:40:16,803 WARN SqlExceptionHelper:144 - SQL Error: -5501, SQLState: 42501 16:40:16,803 WARN SqlExceptionHelper:144 - SQL Error: -5501, SQLState: 42501 16:40:16,803 ERROR SqlExceptionHelper:146 - user lacks privilege or object not found: DEVICES 16:40:16,803 ERROR SqlExceptionHelper:146 - user lacks privilege or object not found: DEVICES 16:40:16,804 ERROR gwt-log:81 - e: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement ... Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement ... Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: DEVICES ... Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: DEVICES ...
<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_2_0.xsd"
version="2.0">
<persistence-unit name="testproject" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>testproject.server.domain.Device</class>
<exclude-unlisted-classes/>
<properties>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />
<property name="hibernate.connection.url" value="jdbc:hsqldb:file:/db/testdb" />
<property name="hibernate.connection.username" value="sa" />
<property name="hibernate.connection.password" value="" />
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size" value="1" />
<!-- SQL dialect -->
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class" value="thread" />
<!-- Disable the second-level cache -->
<property name="cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
<!-- Echo all executed SQL to stdout -->
<!-- <property name="hibernate.show_sql" value="true" /> -->
<!-- <property name="hibernate.format_sql" value="true" /> -->
<!-- Drop and re-create the database schema on startup -->
<!-- This property should not be set in PRODUCTION environments -->
<!-- <property name="hibernate.hbm2ddl.auto" value="create" /> -->
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.max_size" value="20" />
<property name="hibernate.c3p0.timeout" value="300" />
<property name="hibernate.c3p0.max_statements" value="50" />
<property name="hibernate.c3p0.idle_test_period" value="3000" />
</properties>
</persistence-unit>
</persistence>
package testproject.server.domain;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import testproject.shared.dto.DeviceDto;
@Entity
@Table(name = "DEVICES")
public class Device implements Serializable {
private static final long serialVersionUID = 8161681740825989132L;
@Id
@Column(name = "DEVICE_ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long deviceId;
@Column(name = "DEVICE_IMAGE")
protected String image;
@Column(name = "DEVICE_FIRMWARE_VERSION")
protected String firmwareVersion;
public Device() {
}
public Device(Long deviceId) {
setDeviceId(deviceId);
}
public Device(DeviceDto device) {
setDeviceId(device.getDeviceId());
setImage(device.getImage());
setFirmwareVersion(device.getFirmwareVersion());
}
public Long getDeviceId() {
return deviceId;
}
public void setDeviceId(Long deviceId) {
this.deviceId = deviceId;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getFirmwareVersion() {
return firmwareVersion;
}
public void setFirmwareVersion(String firmwareVersion) {
this.firmwareVersion = firmwareVersion;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Device Id: ").append(getDeviceId()).append(", ");
sb.append("Image: ").append(getImage()).append(", ");
sb.append("Firmware Version: ").append(getFirmwareVersion());
return sb.toString();
}
//TODO: Do we need that?
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((deviceId == null) ? 0 : deviceId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof Device))
return false;
Device other = (Device) obj;
if (deviceId == null) {
if (other.deviceId != null)
return false;
} else if (!deviceId.equals(other.deviceId))
return false;
return true;
}
}
package testproject.server.dao;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;
import testproject.server.domain.Device;
public class DeviceDao extends BaseDao {
private static final EntityManagerFactory entityManagerFactory =
Persistence.createEntityManagerFactory("testproject");
public static EntityManager createEntityManager() {
return entityManagerFactory.createEntityManager();
}
public Long createObject(Object object) {
return createDevice((Device) object);
}
public List<Object> retrieveObjects(int maxResults, int firstResult) {
EntityManager em = createEntityManager();
List<Object> list = null;
try {
TypedQuery<Object> query = em.createQuery(
"select a from Device a", Object.class);
query.setMaxResults(maxResults);
query.setFirstResult(firstResult);
list = query.getResultList();
} finally {
em.close();
}
return list;
}
public Long createDevice(Device Device) {
// For an application-managed entity manager its best practice to create
// a
// new entity manager inside a method and close it before the method is
// finished.
EntityManager em = createEntityManager();
EntityTransaction tx = em.getTransaction();
Long DeviceId = -1L;
try {
tx.begin();
em.persist(Device);
DeviceId = Device.getDeviceId();
tx.commit();
} catch (Throwable t) {
t.printStackTrace();
tx.rollback();
} finally {
em.close();
}
return DeviceId;
}
public Device retrieveDevice(Long DeviceId) {
EntityManager em = createEntityManager();
Device Device = null;
try {
TypedQuery<Device> query = em.createQuery(
"select a from Device a where a.DeviceId = ?1",
Device.class);
query.setParameter(1, DeviceId);
Device = query.getSingleResult();
} finally {
em.close();
}
return Device;
}
public List<Device> retrieveDevices(int maxResults, int firstResult) {
EntityManager em = createEntityManager();
List<Device> list = null;
try {
TypedQuery<Device> query = em.createQuery(
"select a from Device a", Device.class);
query.setMaxResults(maxResults);
query.setFirstResult(firstResult);
list = query.getResultList();
} finally {
em.close();
}
return list;
}
public Device updateDevice(Device Device) {
EntityManager em = createEntityManager();
EntityTransaction tx = em.getTransaction();
Device Device2 = null;
try {
tx.begin();
Device2 = em.merge(Device);
tx.commit();
} catch (Throwable t) {
t.printStackTrace();
tx.rollback();
} finally {
em.close();
}
return Device2;
}
public void deleteDevice(Device Device) {
EntityManager em = createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
em.remove(em.merge(Device));
tx.commit();
} catch (Throwable t) {
t.printStackTrace();
tx.rollback();
} finally {
em.close();
}
}
}
package testproject.server;
import java.util.List;
import org.apache.log4j.xml.DOMConfigurator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.allen_sauer.gwt.log.client.Log;
import testproject.server.dao.DeviceDao;
import testproject.server.domain.Device;
public class DeviceTestCase {
private long startTimeMillis;
@Before
public void setUp() {
// The log4j configuration file must be in the Project's root directory
DOMConfigurator.configure("log4j.xml");
startTimeMillis = System.currentTimeMillis();
}
@Test
public void testDeviceDao() {
try {
Log.debug("testDeviceDao()");
createDevices();
}
catch (Exception e) {
Log.error("e: " + e);
e.printStackTrace();
}
}
public void createDevice() {
Device d1 = new Device();
d1.setFirmwareVersion("Firmware1");
d1.setImage("Image1");
DeviceDao deviceDao = new DeviceDao();
deviceDao.createDevice(d1);
}
public void createDevices() {
Device d1 = new Device();
d1.setFirmwareVersion("Firmware1");
d1.setImage("Image1");
Device d2 = new Device();
d1.setFirmwareVersion("Firmware2");
d1.setImage("Image2");
Device d3 = new Device();
d1.setFirmwareVersion("Firmware3");
d1.setImage("Image3");
DeviceDao deviceDao = new DeviceDao();
deviceDao.createDevice(d1);
deviceDao.createDevice(d2);
deviceDao.createDevice(d3);
List<Device> devices = deviceDao.retrieveDevices(100, 0);
for (Device device : devices) {
Log.debug(device.toString());
}
//TODO: Btw, this is not a really good test case ;)
}
@After
public void tearDown() {
long endTimeMillis = System.currentTimeMillis();
float durationSeconds = (endTimeMillis - startTimeMillis) / 1000F;
Log.debug("Duration: " + durationSeconds + " seconds");
}
}
最佳答案
您收到的消息是 HSQLDB 有点神秘的方式,它告诉您您尝试从中选择的 DEVICES 表不存在(或者您正在连接的用户无权访问该表)。创造它。
关于hibernate - HSQLDB 和 Hibernate : Unit Test raises org. hsqldb.HsqlException: 用户缺少权限或找不到对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23634846/
我有以下功能: fun process(t: T, call: (U) -> Unit, map: (T) -> U) = call(map(t)) fun processEmpty(t: T,
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 4年前关闭。 Improve this questi
我正在实现 SVG Tiny 1.1,但我无法理解“用户单元”的概念。 SVG 1.1 规范将每个没有指定单位(例如“mm”、“cm”、“pt”等)的 定义为“用户单位”。 在实现接口(interfa
我正在学习本教程 - http://blog.dasberg.nl/getting-your-frontend-code-quality-in-order/ - 将前端质量指标推送到 SonarQub
我用了 rails new app --skip-test-unit 因为最初,我认为我可以稍后添加测试。 我开发了我的应用程序的很大一部分。 现在,我想添加 Test::Unit 但我找不到任何有关
您如何对由某些报表引擎(例如Crystal Reports或SQL Server Reporting Services)创建的报表进行“单元测试”? 最佳答案 报告的问题类似于GUI的问题。 如果报表
今天在 Proggit 上,我正在阅读题为“Why Unit Testing Is A Waste of Time”的提交的评论线程。 我并不真正关心文章的前提,而是关心 comment对此作出: T
“单元测试”属于白盒测试还是黑盒测试?还是与其他两种测试完全不同? 最佳答案 我觉得这个article by Kent Beck更多地引用 TDD 和单元测试很好地总结了这一点。基本上,这取决于您实际
这是代码: def filterAcc(p: Tweet => Boolean, acc: TweetSet): TweetSet = { foreach(tweet => if(p(el
我打算编写一个抽象类来测试我所有的 DTO 和 DOMAIN 对象。此类将采用可模板对象(通用类型)并使用反射来获取其中的属性类型,并将一些默认值分配给标识的原始类型,稍后将通过访问它们来断言这些类型
我有一个像这样的简单容器特征: trait Handler { def apply[In, Out](in: In): Out } 当我尝试实现它时: new Handler { def ap
为什么这样编译 scala> import scala.concurrent.Future import scala.concurrent.Future scala> val f: Unit = Fu
您使用什么样的实践来使您的代码对单元测试更加友好? 最佳答案 TDD——首先编写测试,强制你要考虑可测试性和帮助编写实际的代码需要的,而不是你认为可能的需要 接口(interface)重构——使得 m
我在elasticsearch中有文本字段,我想在kibana上可视化词云... 第一步,我们需要标记它们,我使用了“标准标记器” ... 使用这种形式的词云可视化结果如下图所示: 但是我需要的是专有
我有以下方法: override def insertAll(notifications: Seq[PushNotificationEncoded]) (i
我的应用程序服务层中有很多方法正在做这样的事情: public void Execute(PlaceOrderOnHoldCommand command) { var order = _rep
一直在使用 Sails.js,但在为 Controller 设计 Jasmine 单元测试时遇到了麻烦。如果这很明显,请原谅我的无知,因为在过去的 3-4 个月里我才深入研究 JavaScript 开
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
在ReKotlin repo README中,有如下代码: data class CounterActionIncrease(val unit: Unit = Unit): Action 代码Unit
我想对一个业务类进行测试,但我遇到了这个问题:其中一个模拟对象与其他类(例如 Sites、URL 和 ComplexObject)有许多依赖关系。 我的问题是:如果我必须在需要测试的方法中使用我的模拟
我是一名优秀的程序员,十分优秀!