Can't create table "system_user" in h2 - java

i am having a problem creating a simple table in h2.
create table system_user (id bigint not null, username varchar(255), primary key (id));
When executing i am getting the error:
Syntax Fehler in SQL Befehl "create table [*]system_user (id bigint not null, username varchar(255), primary key (id))"; erwartet "identifier"
Syntax error in SQL statement "create table [*]system_user (id bigint not null, username varchar(255), primary key (id))"; expected "identifier"; SQL statement:
create table system_user (id bigint not null, username varchar(255), primary key (id)) [42001-210] 42001/42001 (Hilfe)
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax Fehler in SQL Befehl "create table [*]system_user (id bigint not null, username varchar(255), primary key (id))"; erwartet "identifier"
Syntax error in SQL statement "create table [*]system_user (id bigint not null, username varchar(255), primary key (id))"; expected "identifier"; SQL statement:
create table system_user (id bigint not null, username varchar(255), primary key (id)) [42001-210]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:521)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:496)
at org.h2.message.DbException.getSyntaxError(DbException.java:265)
at org.h2.command.Parser.readIdentifier(Parser.java:5759)
at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:5719)
at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:5748)
at org.h2.command.Parser.parseCreateTable(Parser.java:9280)
at org.h2.command.Parser.parseCreate(Parser.java:6779)
at org.h2.command.Parser.parsePrepared(Parser.java:746)
at org.h2.command.Parser.parse(Parser.java:674)
at org.h2.command.Parser.parse(Parser.java:644)
at org.h2.command.Parser.prepareCommand(Parser.java:551)
at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:615)
at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:553)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1116)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:237)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:223)
at org.h2.server.web.WebApp.getResult(WebApp.java:1339)
at org.h2.server.web.WebApp.query(WebApp.java:1137)
at org.h2.server.web.WebApp$1.next(WebApp.java:1103)
at org.h2.server.web.WebApp$1.next(WebApp.java:1090)
at org.h2.server.web.WebThread.process(WebThread.java:189)
at org.h2.server.web.WebThread.run(WebThread.java:102)
at java.base/java.lang.Thread.run(Thread.java:833)
Does anyone have the same problem?

Related

Why a SQL SELECT statement doesn't return COUNT() result on Java Spring boot project?

this is my first question here so, please ask if you need more information. I am working on a personal project. I have a relatively complex relational database structure. I create schema.sql on my spring boot project as well as data.sql with sample data. I try to create a web application for simulated fitness centre web pages. I try to display the location name and number of visits for the user. I create a userLocation bean for keeping the result set as a list of the select query. I can test the statement on H2 database and its work. However, on my code, I cannot get the number of visits from the select statement.
Here is my userlocation bean,
#Data
#NoArgsConstructor
public class UserLocation {
private String locName;
private int numOfVisit;
}
Controller class getMapping method
#GetMapping("/secure/userLocation")
public String myLocation(Model model, Authentication authentication) {
String email = authentication.getName();
User currentUser = da.findUserAccount(email);
model.addAttribute("myLocationList", da.getUserLocationList(currentUser.getUserId()));
return "/secure/userLocation";
}
Here database access method;
public List<UserLocation> getUserLocationList(Long userId) {
MapSqlParameterSource namedParameters = new MapSqlParameterSource();
String query = "SELECT l.locName, COUNT(ul.dayOfVisit) FROM location l "
+ "INNER JOIN userLocation ul ON l.locId = ul.locId "
+ "INNER JOIN sec_user sc ON ul.userId = sc.userId "
+ "WHERE sc.userId = :userId AND ul.locId = 1"
+ "GROUP BY l.locName";
namedParameters.addValue("userId", userId);
return jdbc.query(query, namedParameters, new BeanPropertyRowMapper<UserLocation>(UserLocation.class));
}
here schema.sql
CREATE TABLE location (
locId BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
locName VARCHAR(75),
locAddress VARCHAR(255),
locPhone VARCHAR(25),
locEmail VARCHAR(75)
);
CREATE TABLE sec_user (
userId BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(75),
lastName VARCHAR(75),
adress VARCHAR(255),
phone VARCHAR(10),
email VARCHAR(75) NOT NULL UNIQUE,
encryptedPassword VARCHAR(128) NOT NULL,
enabled BIT NOT NULL
);
CREATE TABLE coach (
coachId BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
coachName VARCHAR(75),
coachLevel BIGINT,
coachRating BIGINT,
aboutMe VARCHAR(255)
);
CREATE TABLE fitnessClass (
classId BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
className VARCHAR(75),
classPrice DOUBLE
);
CREATE TABLE generalCert (
certId BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
certName VARCHAR(75)
);
CREATE TABLE certCoach (
certId BIGINT NOT NULL,
coachId BIGINT NOT NULL
);
ALTER TABLE certCoach
ADD CONSTRAINT certCoach_FK1 FOREIGN KEY (certId)
REFERENCES generalCert (certId);
ALTER TABLE certCoach
ADD CONSTRAINT certCoach_FK2 FOREIGN KEY (coachId)
REFERENCES coach (coachId);
CREATE TABLE userLocation (
userLocId BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
locId BIGINT NOT NULL,
userId BIGINT NOT NULL,
isHomeLoc BIT,
dayOfVisit DATE
);
ALTER TABLE userLocation
ADD CONSTRAINT userLocation_FK1 FOREIGN KEY (locId)
REFERENCES location (locId);
ALTER TABLE userLocation
ADD CONSTRAINT userLocation_FK2 FOREIGN KEY (userId)
REFERENCES sec_user (userId);
CREATE TABLE amenity (
amenityId BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
amenityName VARCHAR(75),
locId BIGINT
);
ALTER TABLE amenity
ADD CONSTRAINT amenity_FK FOREIGN KEY (locId)
REFERENCES location (locId);
CREATE TABLE room (
roomId BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
roomName VARCHAR(75),
locId BIGINT
);
ALTER TABLE room
ADD CONSTRAINT room_FK FOREIGN KEY (locId)
REFERENCES location (locId);
CREATE TABLE classCoach (
classId BIGINT NOT NULL,
coachId BIGINT NOT NULL
);
ALTER TABLE classCoach
ADD CONSTRAINT classCoachFK1 FOREIGN KEY (classId)
REFERENCES fitnessClass(classId);
ALTER TABLE classCoach
ADD CONSTRAINT classCoachFK2 FOREIGN KEY (coachId)
REFERENCES coach(coachId);
CREATE TABLE schedule (
ScheduleId BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
ScheduleDate DATE,
ScheduleTime TIME,
RoomId BIGINT,
ClassId BIGINT NOT NULL,
LocId BIGINT NOT NULL
);
ALTER TABLE schedule
ADD CONSTRAINT scheduleFK1 FOREIGN KEY (roomId)
REFERENCES room(RoomId);
ALTER TABLE schedule
ADD CONSTRAINT scheduleFK2 FOREIGN KEY (classId)
REFERENCES fitnessClass(classId);
ALTER TABLE schedule
ADD CONSTRAINT ScheduleFK3 FOREIGN KEY (LocId)
REFERENCES location(LocId);
CREATE TABLE reservation (
ClassId BIGINT NOT NULL,
userId BIGINT NOT NULL
);
ALTER TABLE reservation
ADD CONSTRAINT reservationFK1 FOREIGN KEY (classId)
REFERENCES fitnessClass(classId);
ALTER TABLE reservation
ADD CONSTRAINT reservationFK2 FOREIGN KEY (userId)
REFERENCES sec_user(userId);
CREATE TABLE workFrom (
coachId BIGINT NOT NULL,
locId BIGINT NOT NULL
);
ALTER TABLE workFrom
ADD CONSTRAINT workFromFK1 FOREIGN KEY (coachId)
REFERENCES coach(coachId);
ALTER TABLE workFrom
ADD CONSTRAINT workFromFK2 FOREIGN KEY (locId)
REFERENCES location(locId);
CREATE TABLE review (
ReviewId BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
CoachId BIGINT NOT NULL,
userId BIGINT NOT NULL,
ReviewDate DATE,
ComScore CHAR(1),
EnthScore CHAR(1),
PunctScore CHAR(1),
ReviewText VARCHAR(500)
);
ALTER TABLE review
ADD CONSTRAINT reviewFK1 FOREIGN KEY (coachId)
REFERENCES coach(coachId);
ALTER TABLE review
ADD CONSTRAINT reviewFK2 FOREIGN KEY (userId)
REFERENCES sec_user(userId);
CREATE TABLE Reference (
CoachId BIGINT NOT NULL,
userId BIGINT NOT NULL
);
ALTER TABLE Reference
ADD CONSTRAINT ReferenceFK1 FOREIGN KEY (coachId)
REFERENCES coach(coachId);
ALTER TABLE review
ADD CONSTRAINT ReferenceFK2 FOREIGN KEY (userId)
REFERENCES sec_user(userId);
CREATE TABLE ClientCoach (
coachId BIGINT NOT NULL,
userId BIGINT NOT NULL,
myCoach BIT
);
ALTER TABLE ClientCoach
ADD CONSTRAINT ClientCoachFK1 FOREIGN KEY (coachId)
REFERENCES coach(coachId);
ALTER TABLE ClientCoach
ADD CONSTRAINT ClientCoachFK2 FOREIGN KEY (userId)
REFERENCES sec_user(userId);
CREATE TABLE sec_role(
roleId BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
roleName VARCHAR(30) NOT NULL UNIQUE
);
CREATE TABLE user_role
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
userId BIGINT NOT NULL,
roleId BIGINT NOT NULL
);
ALTER TABLE user_role
ADD CONSTRAINT user_role_uk UNIQUE (userId, roleId);
ALTER TABLE user_role
ADD CONSTRAINT user_role_fk1 FOREIGN KEY (userId)
REFERENCES sec_user (userId);
ALTER TABLE user_role
ADD CONSTRAINT user_role_fk2 FOREIGN KEY (roleId)
REFERENCES sec_role (roleId);
Here the result web page
Here is EERD for the schema
Please try:
SELECT l.locName, COUNT(ul.dayOfVisit) AS numOfVisit -- ...
(to alias numOfVisit), since we are using a BeanPropertyRowMapper (which mapps by "bean properties" (i.e. "field names"): https://www.google.com/search?q=java+bean+naming+conventions).
Alternatively use an other/custom RowMapper.
And since even javadoc recommends:
... For best performance, consider using a custom RowMapper implementation.
Best:
return jdbc.query(query, namedParameters,
(ResultSet rs, int rowNum) -> { // one ResultSet per row:
// column indices start with 1(!):
return new UserLocation(rs.getString(1), rs.getInt(2));
// alternatively (name based): rs.getString("locName")...
}
);
;)
RowMapper javadoc (spring-jdbc:current)
ResultSet javadoc (jdk17)
and since RowMapper is a/meets the requirements of a functional interface, we can write it as lambda expression.

FOREIGN KEY ON UPDATE CASCADE, Syntax error: Encountered "CASCADE"

I have made a Users and Items table successfully using JDBC in NetBeans but executing the next two CREATE commands is giving errors.
[Exception, Error code 30,000, SQLState 42X01] Syntax error: Encountered "CASCADE" at line 10, column 19.
The same error for the Orders and Cart table.
CREATE TABLE Users(
FName VARCHAR(60),
LName VARCHAR(60),
Email VARCHAR(60),
UName VARCHAR(30) NOT NULL,
PWord VARCHAR(60),
PRIMARY KEY(UName)
);
CREATE TABLE Items(
INumber INT NOT NULL,
IName VARCHAR(80),
IPrice FLOAT,
QtyAvailable INT CHECK(QtyAvailable>=0),
IDescription VARCHAR(200),
PRIMARY KEY(INumber)
);
CREATE TABLE Cart(
CartID INT NOT NULL AUTO_INCREMENT,
Username VARCHAR(30) NOT NULL,
ItemNumber INT NOT NULL,
Qty INT,
PRIMARY KEY(CartID),
constraint userIDFK
FOREIGN KEY (Username) REFERENCES Users(UName)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT itemIDFK
FOREIGN KEY (ItemNumber) REFERENCES Items(INumber)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE Orders(
ONumber INT NOT NULL AUTO_INCREMENT,
ODate VARCHAR(20),
OUName VARCHAR(30) NOT NULL,
OItemNumber INT NOT NULL,
Qty INT,
UnitPrice FLOAT,
OComplete VARCHAR(3),
CardName VARCHAR(20),
CardNumer DOUBLE,
CSV INT,
ExpDate VARCHAR(11),
Email VARCHAR(60),
PRIMARY KEY(ONumber),
constraint ouserIDFK
FOREIGN KEY (OUName) REFERENCES Users(UName)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT oitemIDFK
FOREIGN KEY (OItemNumber) REFERENCES Items(INumber)
ON DELETE CASCADE
ON UPDATE CASCADE
);
I had looked for a solution and I had found this a bit relateable can someone please help me out with the code.
https://stackoverflow.com/a/30697331/6766368

Error generating .war file JHipster

I am trying to export the .war file but at the time of doing clean and build it throws me errors of liquibase. In the IDE run perfectly fine.
I stress that this happened after adding some roles as indicated in this question: Using ROLES in jhipster?
This is the error thrown by the console:
2018-02-27 11:20:40.764 WARN 8156 --- [as-4-Executor-1] i.g.j.c.liquibase.AsyncSpringLiquibase : Starting Liquibase asynchronously, your database might not be ready at startup!
2018-02-27 11:20:43.048 ERROR 8156 --- [as-4-Executor-1] liquibase : classpath:config/liquibase/master.xml: config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster: Change Set config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster failed. Error: Tabla "JHI_USER" ya existe
Table "JHI_USER" already exists; SQL statement:
CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email)) [42101-196] [Failed SQL: CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email))]
2018-02-27 11:20:43.110 ERROR 8156 --- [as-4-Executor-1] i.g.j.c.liquibase.AsyncSpringLiquibase : Liquibase could not start correctly, your database is NOT ready: Migration failed for change set config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster:
Reason: liquibase.exception.DatabaseException: Tabla "JHI_USER" ya existe
Table "JHI_USER" already exists; SQL statement:
CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email)) [42101-196] [Failed SQL: CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email))]
liquibase.exception.MigrationFailedException: Migration failed for change set config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster:
Reason: liquibase.exception.DatabaseException: Tabla "JHI_USER" ya existe
Table "JHI_USER" already exists; SQL statement:
CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email)) [42101-196] [Failed SQL: CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email))]
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:619)
at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:51)
at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:79)
at liquibase.Liquibase.update(Liquibase.java:214)
at liquibase.Liquibase.update(Liquibase.java:192)
at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:431)
at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:388)
at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.initDb(AsyncSpringLiquibase.java:82)
at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.lambda$afterPropertiesSet$0(AsyncSpringLiquibase.java:64)
at io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor.lambda$createWrappedRunnable$1(ExceptionHandlingAsyncTaskExecutor.java:66)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: liquibase.exception.DatabaseException: Tabla "JHI_USER" ya existe
Table "JHI_USER" already exists; SQL statement:
CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email)) [42101-196] [Failed SQL: CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email))]
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:309)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:113)
at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1277)
at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1259)
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:582)
... 12 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLException: Tabla "JHI_USER" ya existe
Table "JHI_USER" already exists; SQL statement:
CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email)) [42101-196]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.command.ddl.CreateTable.update(CreateTable.java:117)
at org.h2.command.CommandContainer.update(CommandContainer.java:101)
at org.h2.command.Command.executeUpdate(Command.java:260)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:192)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:164)
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:92)
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:307)
... 17 common frames omitted
´
2018-02-27 11:20:49.728 DEBUG 8156 --- [ restartedMain] i.g.j.c.apidoc.SwaggerConfiguration : Starting Swagger
2018-02-27 11:20:49.729 DEBUG 8156 --- [ restartedMain] i.g.j.c.apidoc.SwaggerConfiguration : Started Swagger in 0 ms
2018-02-27 11:20:51.944 INFO 8156 --- [ restartedMain] municipalidad.obras.ObrasPrivadas4App : Started ObrasPrivadas4App in 17.765 seconds (JVM running for 18.308)
2018-02-27 11:20:51.945 INFO 8156 --- [ restartedMain] municipalidad.obras.ObrasPrivadas4App :
----------------------------------------------------------
Application 'obrasPrivadas4' is running! Access URLs:
Local: http://localhost:8080
External: http://192.168.48.28:8080
Profile(s): [swagger, dev]
----------------------------------------------------------
´
I would greatly appreciate your help. Sorry for the bad English.

Hibernate Mapping Map<String,String>

I use Hibernate 4.3.11 with H2 Database. I have a class in Java with several maps with annotations. Persisting works fine but my map in my H2 Database has no entries.
#ElementCollection
#MapKeyColumn(name = "key")
#CollectionTable(name = "value", joinColumns = #JoinColumn(name = "sabilanz_id"))
#Column(name = "value")
private Map<String, String> sonstAnlagen;
My H2 output:
select * from saBilanz_sonstanlagen;
SABILANZ_ID VALUE KEY
(keine Datensätze, 8 ms)
MYSQL Dump
CREATE USER IF NOT EXISTS SA SALT '7f72b2df54de3e6a' HASH '11116078543527d2f2c87f3df156e18f71f7d1bc0e5a7a7653d22512c9de2994' ADMIN;
CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_8A6BCC6F_6599_4635_8D43_45F8DC56F9AD START WITH 65 BELONGS_TO_TABLE;
CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_644997FC_AAC3_4D75_B453_FD4E56B7D326 START WITH 65 BELONGS_TO_TABLE;
CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_61E73E74_EF49_4B3E_AA95_432C69B31DDB START WITH 65 BELONGS_TO_TABLE;
CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_3CF73C6A_6FE2_4978_BD20_EAC744ED7F25 START WITH 65 BELONGS_TO_TABLE;
CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_676C7731_65A8_41CA_9097_14C131188E32 START WITH 65 BELONGS_TO_TABLE;
CREATE CACHED TABLE PUBLIC.BILANZ(
ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_676C7731_65A8_41CA_9097_14C131188E32) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_676C7731_65A8_41CA_9097_14C131188E32,
AKTIVA VARCHAR(255),
ANLAGEVERMOEGEN VARCHAR(255),
BUCHUNGSKREIS VARCHAR(255),
EIGENKAPITAL VARCHAR(255),
FINANZANLAGEN VARCHAR(255),
FORDERUNGEN VARCHAR(255),
GEWINNRUECKLAGEN VARCHAR(255),
GEZEICHNETESKAPITAL VARCHAR(255),
IMMATERIELLEVERMOEGENSGEGENSTAENDE VARCHAR(255),
JAHRESUEBERSCHUSS VARCHAR(255),
KAPITALRUECKLAGE VARCHAR(255),
LIQUIDEMITTEL VARCHAR(255),
PASSIVA VARCHAR(255),
PERIODE VARCHAR(255),
RUECKSTELLUNGEN VARCHAR(255),
SACHANLAGEN VARCHAR(255),
UMLAUFVERMOEGEN VARCHAR(255),
VERBINDLICHKEITEN VARCHAR(255),
VORRAETE VARCHAR(255),
WAEHRUNG VARCHAR(255),
WERTPAPIERE VARCHAR(255)
);
ALTER TABLE PUBLIC.BILANZ ADD CONSTRAINT PUBLIC.CONSTRAINT_7 PRIMARY KEY(ID);
-- 2 +/- SELECT COUNT(*) FROM PUBLIC.BILANZ;
INSERT INTO PUBLIC.BILANZ(ID, AKTIVA, ANLAGEVERMOEGEN, BUCHUNGSKREIS, EIGENKAPITAL, FINANZANLAGEN, FORDERUNGEN, GEWINNRUECKLAGEN, GEZEICHNETESKAPITAL, IMMATERIELLEVERMOEGENSGEGENSTAENDE, JAHRESUEBERSCHUSS, KAPITALRUECKLAGE, LIQUIDEMITTEL, PASSIVA, PERIODE, RUECKSTELLUNGEN, SACHANLAGEN, UMLAUFVERMOEGEN, VERBINDLICHKEITEN, VORRAETE, WAEHRUNG, WERTPAPIERE) VALUES
(1, '981561.00', '738090.00', '1000', '694549.00', '645086.00', '82568.00', '539628.00', '75054.00', '33256.00', '79468.00', '399.00', '5396.00', '981561.00', '2015.01', '97138.00', '59748.00', '243471.00', '189874.00', '124393.00', 'EUR', '31114.00'),
(33, '981561.00', '738090.00', '1000', '694549.00', '645086.00', '82568.00', '539628.00', '75054.00', '33256.00', '79468.00', '399.00', '5396.00', '981561.00', '2015.01', '97138.00', '59748.00', '243471.00', '189874.00', '124393.00', 'EUR', '31114.00');
CREATE CACHED TABLE PUBLIC.GUV(
ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_61E73E74_EF49_4B3E_AA95_432C69B31DDB) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_61E73E74_EF49_4B3E_AA95_432C69B31DDB,
ABSCHREIBUNGEN VARCHAR(255),
BESTANDSVERAENDERUNGEN VARCHAR(255),
BETRIEBSERGEBNIS VARCHAR(255),
BILANZGEWINNBILANZVERLUST VARCHAR(255),
ERGEBNISDERGEWOEHNLICHENGESCHAEFTSTAETIGKEIT VARCHAR(255),
ERTRAEGEAUSBETEILIGUNGEN VARCHAR(255),
FINANZERGEBNIS VARCHAR(255),
MATERIALAUFWAND VARCHAR(255),
PERSONALAUFWAND VARCHAR(255),
SONSTIGEBETRIEBLICHEAUFWENDUNGEN VARCHAR(255),
SONSTIGEBETRIEBLICHEERTRAEGE VARCHAR(255),
STEUERN VARCHAR(255),
UMSATZERLOESE VARCHAR(255),
ZINSAUFWENDUNGEN VARCHAR(255),
ZINSERTRAEGE VARCHAR(255)
);
ALTER TABLE PUBLIC.GUV ADD CONSTRAINT PUBLIC.CONSTRAINT_1 PRIMARY KEY(ID);
-- 2 +/- SELECT COUNT(*) FROM PUBLIC.GUV;
INSERT INTO PUBLIC.GUV(ID, ABSCHREIBUNGEN, BESTANDSVERAENDERUNGEN, BETRIEBSERGEBNIS, BILANZGEWINNBILANZVERLUST, ERGEBNISDERGEWOEHNLICHENGESCHAEFTSTAETIGKEIT, ERTRAEGEAUSBETEILIGUNGEN, FINANZERGEBNIS, MATERIALAUFWAND, PERSONALAUFWAND, SONSTIGEBETRIEBLICHEAUFWENDUNGEN, SONSTIGEBETRIEBLICHEERTRAEGE, STEUERN, UMSATZERLOESE, ZINSAUFWENDUNGEN, ZINSERTRAEGE) VALUES
(1, '13461.00', '15717.00', '45276.00', '79468.00', '104102.00', '65202.00', '58826.00', '476269.00', '121990.00', '229256.00', '112319.00', '24634.00', '758216.00', '9583.00', '3207.00'),
(33, '13461.00', '15717.00', '45276.00', '79468.00', '104102.00', '65202.00', '58826.00', '476269.00', '121990.00', '229256.00', '112319.00', '24634.00', '758216.00', '9583.00', '3207.00');
CREATE CACHED TABLE PUBLIC.ROI(
ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_8A6BCC6F_6599_4635_8D43_45F8DC56F9AD) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_8A6BCC6F_6599_4635_8D43_45F8DC56F9AD,
ROI VARCHAR(255)
);
ALTER TABLE PUBLIC.ROI ADD CONSTRAINT PUBLIC.CONSTRAINT_13 PRIMARY KEY(ID);
-- 2 +/- SELECT COUNT(*) FROM PUBLIC.ROI;
INSERT INTO PUBLIC.ROI(ID, ROI) VALUES
(1, '0.15'),
(33, '0.15');
CREATE CACHED TABLE PUBLIC.SABILANZ_SONSTANLAGEN(
SABILANZ_ID BIGINT NOT NULL,
VALUE VARCHAR(255),
KEY VARCHAR(255) NOT NULL
);
ALTER TABLE PUBLIC.SABILANZ_SONSTANLAGEN ADD CONSTRAINT PUBLIC.CONSTRAINT_7C PRIMARY KEY(SABILANZ_ID, KEY);
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.SABILANZ_SONSTANLAGEN;
CREATE CACHED TABLE PUBLIC.UHV(
ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_3CF73C6A_6FE2_4978_BD20_EAC744ED7F25) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_3CF73C6A_6FE2_4978_BD20_EAC744ED7F25,
UMSCHLAGSHAEUFIGKEITSVERMOEGEN VARCHAR(255)
);
ALTER TABLE PUBLIC.UHV ADD CONSTRAINT PUBLIC.CONSTRAINT_14 PRIMARY KEY(ID);
-- 2 +/- SELECT COUNT(*) FROM PUBLIC.UHV;
INSERT INTO PUBLIC.UHV(ID, UMSCHLAGSHAEUFIGKEITSVERMOEGEN) VALUES
(1, '2.5'),
(33, '2.5');
CREATE CACHED TABLE PUBLIC.UMSATZRENDITE(
ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_644997FC_AAC3_4D75_B453_FD4E56B7D326) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_644997FC_AAC3_4D75_B453_FD4E56B7D326,
UMSATZRENDITE VARCHAR(255)
);
ALTER TABLE PUBLIC.UMSATZRENDITE ADD CONSTRAINT PUBLIC.CONSTRAINT_6 PRIMARY KEY(ID);
-- 2 +/- SELECT COUNT(*) FROM PUBLIC.UMSATZRENDITE;
INSERT INTO PUBLIC.UMSATZRENDITE(ID, UMSATZRENDITE) VALUES
(1, '6'),
(33, '6');
ALTER TABLE PUBLIC.SABILANZ_SONSTANLAGEN ADD CONSTRAINT PUBLIC.FK_698G1BM2MSCHIYFFSB12ONGIR FOREIGN KEY(SABILANZ_ID) REFERENCES PUBLIC.BILANZ(ID) NOCHECK;
You didn't insert any value into saBilanz_sonstanlagen table. It's normal that it doesn't have any record.

MySQLIntegrityConstraintViolationException: Cannot add or update a child row

My view add.scala.html is this
So if i add a product it shows on same screen and i have a delete button to delete product.My problem is that when i add new product it works fine but when i add a new product after deleting any one then it gives me the error
[PersistenceException: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`shopdb`.`product_shop`, CONSTRAINT `fk_product_shop_product_01` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`))]
on my models.Product.java
public static Product create(Product product,Shop shop) {
product.save();
static List<Product> products = new ArrayList<>();
products.add(product);
shop.products = products;
shop.save();//getting error on this line
return product;
}
public static void delete(Long id) {
find.ref(id).delete();
}
my database
create table product (
id bigint auto_increment not null,
name varchar(255),
price float,
category varchar(255),
constraint pk_product primary key (id))
;
create table shop (
id bigint auto_increment not null,
name varchar(255),
address_line1 varchar(255),
address_line2 varchar(255),
address_line3 varchar(255),
city varchar(255),
town varchar(255),
phone_number varchar(255),
category varchar(255),
shop_pic longblob,
owner_id bigint,
constraint pk_shop primary key (id))
;
create table product_shop (
product_id bigint not null,
shop_id bigint not null,
constraint pk_product_shop primary key (product_id, shop_id))
;
alter table product_shop add constraint fk_product_shop_product_01 foreign key (product_id) references product (id) on delete restrict on update restrict;
alter table product_shop add constraint fk_product_shop_shop_02 foreign key (shop_id) references shop (id) on delete restrict on update restrict;
Any help would be really appreciated.
Why are you assigning
shop.products = products;
shouldn't you do
shop.products.add(products); ?

Categories

Resources