derby

JPA / Hibernate / Derby TableGenerator use negative values

核能气质少年 提交于 2019-12-14 02:14:52
问题 I want any generated primary keys in my database to be negative integers. I defined a TableGenerator: <table-generator name="MY_SEQ" table="MY_SEQUENCE_TABLE" initial-value="-1000000" allocation-size="1" /> I assumed this would start the first generated key at -1000000 and increment each id by 1. So the next id would be -999999. When I create and persist a new entity I get the following error: java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have

Derby SQL Timestamp Arithmetic and JDBC escape syntax

…衆ロ難τιáo~ 提交于 2019-12-14 01:55:14
问题 I have two columns in my table, Created(TIMESTAMP) and lifetime(BIGINT). Lifetime is represented as seconds. I would like to add the lifetime column to the timestamp column and compare that result to another date. I referenced the derby manual and found support for TIMESTAMPADD in the "JDBC escape syntax for fn keyword" section: {fn functionCall} TIMESTAMPADD( interval, integerExpression, timestampExpression ) Okay so I tried: SELECT i.messageId FROM ServerMessageEntity i WHERE {fn

Derby foreign key constraint

风流意气都作罢 提交于 2019-12-13 19:01:20
问题 What's the problem with this statement that gives me the following exception? s.addBatch("CREATE TABLE category ( id SMALLINT NOT NULL GENERATED ALWAYS AS IDENTITY \n" + "\t(START WITH 0, INCREMENT BY 1), title VARCHAR(100))\n" ); s.addBatch("CREATE TABLE task (id SMALLINT NOT NULL GENERATED ALWAYS AS IDENTITY \n" + "\t(START WITH 0, INCREMENT BY 1), title VARCHAR(100), cat_id INT, visible BOOLEAN, " + "deprecated BOOLEAN" + "CONSTRAINT fk_cat_id FOREIGN KEY (cat_id)\n" + "\tREFERENCES

connection.getMetaData does not seem to return table info

☆樱花仙子☆ 提交于 2019-12-13 17:41:03
问题 I am using a simple app to aid learning database with Apache.Derby and working in Eclipse. The following code runs ok but conn.getMetaData() does not return anything meaningful regarding the table - colnameslist.size for example is 0. However I added meta.getDatabaseProductName() to see what happened and that returns 'Apache.Derby' so I guess there is some sort of connection. The connection url is "jdbc:derby:C:/Users/RonLaptop/MyDB". The string passed into getTableContents() is "MYENERGYAPP

Unable to update the table where pimary key is located

删除回忆录丶 提交于 2019-12-13 16:27:25
问题 Please have a look the following code public String setEmailAccount(String account,String userName, String password) { createConnection(); String result = ""; try { //This part will set the new account con.setAutoCommit(false); PreparedStatement ps = con.prepareStatement("insert into Emails values (?,?,?)"); ps.setString(1,account); ps.setString(2, userName); ps.setString(3, password); int resultInt = ps.executeUpdate(); con.commit(); if(resultInt>0) { result = "Account Created Successfully";

Configuration error. Class [org.apache.derby.jdbc.EmbeddedDriver] not found while connecting to DB

一世执手 提交于 2019-12-13 16:04:24
问题 I am using the command mvn exec:java to run my application from cmd .My Persistence.xml properties are is : <properties> <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" /> <property name="javax.persistence.jdbc.url" value="jdbc:derby:DB;create=true" /> <property name="javax.persistence.jdbc.user" value="test" /> <property name="javax.persistence.jdbc.password" value="test" /> <!-- EclipseLink should create the database schema automatically -->

Latest Hibernate and Derby: Unable to make JDBC Connection

被刻印的时光 ゝ 提交于 2019-12-13 15:17:03
问题 I'm trying to create a barebones project that uses Hibernate to connect to a Derby database. I'm using the latest versions of both Hibernate and Derby, but I get a generic Unable to make JDBC Connection error. Here is my pom.xml file: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId

Limit Derby Log File Size

亡梦爱人 提交于 2019-12-13 14:52:19
问题 Our app sends the contents of the derby.log file to our server whenever Apache Derby throws a SQLException in our app. In order to get detailed logs, we are setting the 'derby.infolog.append' property to true. However, we are noticing enormously large logs files since the logs also contain bootup output each time a connection is made to the database. NOTE: we are using Derby in embedded mode. Is there a way to have derby limit the total number of lines it logs to derby.log file? For example,

How to set up @Id field properly when database table is already populated JPA

Deadly 提交于 2019-12-13 14:34:21
问题 I am having a single table in my database and I have added the @Id attribute over the field. As strategy I use GenerationType.IDENTITY . This works fine WHEN the database table is not already populated by rows from a SQL script. How can I manage to get it to work when the table already has some rows in it? Because it doesn't work when I am trying to insert entities from my application when it is pre-populated. I am using Derby database for this and eclipselink as implementation. 回答1: Use

Can I use MERGE INTO to simulate “upsert” in Apache Derby?

时间秒杀一切 提交于 2019-12-13 13:34:34
问题 We're using Derby and have a lot of code which goes like this: try (ResultSet rs = executeQuery(...)) { if (rs.next()) { updateRowSet(rs, ...); rs.updateRow(); } else { executeUpdate(...); } } In the past, we were searching for a way to do this logic server-side, and found that some databases supported an "upsert" (update or insert) operation. Derby had a feature request for MERGE INTO which was supposedly the SQL:2003 standard way of doing this, so we sat and watched the ticket, and much