Ich habe Probleme, die Ausgabe der Spring Boot Console zu interpretieren.
Ich erhalte ein DTO-Objekt als Parameter und speichere den Inhalt in das andere Objekt und schließlich in die persistente Datenbank.
Wenn ich das Objekt über das Formular im Frontend erstelle und an das Backend sende, wird es von dieser Methode verarbeitet (nicht wundern über das Chaos):
Hier prüfe ich genau wo das Problem liegt:
ich prüfe zuerst DTO Object, danach das Entity Objekt (ProductObject), ob die characteristic Property einen falschen Wert beinhaltet und zum Schluss speichere ich das Ganze. SpringBoot liefert mir folgende Fehler-Anzeige:
Das komische daran ist, wenn ich das Objekt mit Postman sende, dann funktioniert alles Problemlos:
Dann wird kein Fehler geworfen und alles funktioniert Problemlos und das Entitiy-Objekt wird persistiert. Jetzt denke ich, dass es hier nicht um die characteristic Property handelt, vielleicht hat jemand eine andere Meinung?
Ich erhalte ein DTO-Objekt als Parameter und speichere den Inhalt in das andere Objekt und schließlich in die persistente Datenbank.
Wenn ich das Objekt über das Formular im Frontend erstelle und an das Backend sende, wird es von dieser Methode verarbeitet (nicht wundern über das Chaos):
Java:
public void save(PuppyDTO puppyDTO) {
System.out.println("---------------------------------Puppy Creaiting Profile------------------------------------" );
puppyDTO.getCharacteristic().forEach(an -> System.out.println("characteristic: " + an.getCharacterName()));
System.out.println(puppyDTO.getCharacteristic().stream().map(an -> " " + an.getCharacterName()));
System.out.println(puppyDTO.getPuppyId() + ", " + puppyDTO.getColor() + ", " + puppyDTO.getRace().getRace());
System.out.println("Characteristic Type: " + puppyDTO.getCharacteristic().getClass());
ProductObject prOb = new ProductObject();
prOb.setCategory(categoryRepository.getReferenceById(1L));
prOb.setPuppyId(puppyDTO.getPuppyId());
prOb.setFoodId(0L);
prOb.setName(puppyDTO.getName());
prOb.setWeight(puppyDTO.getWeight());
prOb.setHeight(puppyDTO.getHeight());
prOb.setPrice(puppyDTO.getPrice());
prOb.setImage(puppyDTO.getImage());
prOb.setCharacteristic(puppyDTO.getCharacteristic());
System.out.print("prOb Characteristic: ");
prOb.getCharacteristic().forEach(ac -> System.out.println(ac.getCharacterName()));
//puppyDTO.getCharacteristic().forEach(ac -> prOb.setSingleCharacter(ac));
prOb.setObjectName("");
prOb.setFoodType(ProductObject.FoodType.NONE);
prOb.setColor(puppyDTO.getColor());
prOb.setCount(1);
Bread bread = new Bread();
bread.setProductObject(prOb); // Setzt die Beziehung von Bread zu ProductObject
bread.setRace(puppyDTO.getRace().getRace());
prOb.setRace(bread); // Setzt die Beziehung von ProductObject zu Bread
// Speichere erst das ProductObject mit der verknüpften Bread-Instanz
prObjectRepository.save(prOb);
System.out.println("Bread -----" + puppyDTO.getRace() + ", ProductObject: " + bread.getProductObject().getPuppyId());
// Optional, da CascadeType.ALL das Bread automatisch mit ProductObject speichern sollte
breadRepository.save(bread);
System.out.println(puppyDTO.getCharacteristic() + ", \n" + puppyDTO.getColor());
puppyDTO.getCharacteristic().forEach(enum_ -> System.out.println("enum: " + enum_.getClass()));
System.out.println("\t\t\tprOb.getPuppyId() : " + prOb.getPuppyId()
+ ", \n\t\t\tprOb.getCharacteristic(): " + prOb.getCharacteristic()
+ ", \n\t\t\tprOb.getColor(): " + prOb.getColor()
+ "");
// Speichern abschließen
prObjectRepository.save(prOb);
System.out.println("Das Objekt: " );
}
ich prüfe zuerst DTO Object, danach das Entity Objekt (ProductObject), ob die characteristic Property einen falschen Wert beinhaltet und zum Schluss speichere ich das Ganze. SpringBoot liefert mir folgende Fehler-Anzeige:
XML:
---------------------------------Puppy Creaiting Profile------------------------------------
characteristic: Reasonable
characteristic: Playful
characteristic: Protective
characteristic: Aggressive
characteristic: Social
characteristic: Independent
java.util.stream.ReferencePipeline$3@7d858cde
25, whiteblack, Dalmatian
Characteristic Type: class java.util.HashSet
prOb Characteristic: Reasonable
Playful
Protective
Aggressive
Social
Independent
2024-12-05T13:25:25.119+01:00 DEBUG 6956 --- [Puppies] [nio-8080-exec-4] org.hibernate.SQL :
insert
into
product_object
(category_id, characteristic, color, count, food_id, food_type, height, image, name, object_name, price, puppy_id, weight, id)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, default)
Hibernate:
insert
into
product_object
(category_id, characteristic, color, count, food_id, food_type, height, image, name, object_name, price, puppy_id, weight, id)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, default)
Verzeichnis ist nicht vorhanden!---------------------------------------------------------------------------
2024-12-05T13:25:25.136+01:00 WARN 6956 --- [Puppies] [nio-8080-exec-4] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 22030, SQLState: 22030
2024-12-05T13:25:25.136+01:00 ERROR 6956 --- [Puppies] [nio-8080-exec-4] o.h.engine.jdbc.spi.SqlExceptionHelper : Wert nicht erlaubt für Feld "('Aggressive', 'Calm', 'Curious', 'Fearful', 'Friendly', 'Independent', 'Loyal', 'None', 'Playful', 'Protective', 'Reasonable', 'Social', 'Vigorous')": "0"
Value not permitted for column "('Aggressive', 'Calm', 'Curious', 'Fearful', 'Friendly', 'Independent', 'Loyal', 'None', 'Playful', 'Protective', 'Reasonable', 'Social', 'Vigorous')": "0"; SQL statement:
insert into product_object (category_id,characteristic,color,count,food_id,food_type,height,image,name,object_name,price,puppy_id,weight,id) values (?,?,?,?,?,?,?,?,?,?,?,?,?,default) [22030-224]
2024-12-05T13:25:25.140+01:00 ERROR 6956 --- [Puppies] [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.dao.DataIntegrityViolationException: could not execute statement [Wert nicht erlaubt für Feld "('Aggressive', 'Calm', 'Curious', 'Fearful', 'Friendly', 'Independent', 'Loyal', 'None', 'Playful', 'Protective', 'Reasonable', 'Social', 'Vigorous')": "0"
Value not permitted for column "('Aggressive', 'Calm', 'Curious', 'Fearful', 'Friendly', 'Independent', 'Loyal', 'None', 'Playful', 'Protective', 'Reasonable', 'Social', 'Vigorous')": "0"; SQL statement:
insert into product_object (category_id,characteristic,color,count,food_id,food_type,height,image,name,object_name,price,puppy_id,weight,id) values (?,?,?,?,?,?,?,?,?,?,?,?,?,default) [22030-224]] [insert into product_object (category_id,characteristic,color,count,food_id,food_type,height,image,name,object_name,price,puppy_id,weight,id) values (?,?,?,?,?,?,?,?,?,?,?,?,?,default)]; SQL [insert into product_object (category_id,characteristic,color,count,food_id,food_type,height,image,name,object_name,price,puppy_id,weight,id) values (?,?,?,?,?,?,?,?,?,?,?,?,?,default)]] with root cause
org.h2.jdbc.JdbcSQLDataException: Wert nicht erlaubt für Feld "('Aggressive', 'Calm', 'Curious', 'Fearful', 'Friendly', 'Independent', 'Loyal', 'None', 'Playful', 'Protective', 'Reasonable', 'Social', 'Vigorous')": "0"
Value not permitted for column "('Aggressive', 'Calm', 'Curious', 'Fearful', 'Friendly', 'Independent', 'Loyal', 'None', 'Playful', 'Protective', 'Reasonable', 'Social', 'Vigorous')": "0"; SQL statement:
insert into product_object (category_id,characteristic,color,count,food_id,food_type,height,image,name,object_name,price,puppy_id,weight,id) values (?,?,?,?,?,?,?,?,?,?,?,?,?,default) [22030-224]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:518) ~[h2-2.2.224.jar:2.2.224]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489) ~[h2-2.2.224.jar:2.2.224]
at org.h2.message.DbException.get(DbException.java:223) ~[h2-2.2.224.jar:2.2.224]
at org.h2.value.ExtTypeInfoEnum.getValue(ExtTypeInfoEnum.java:154) ~[h2-2.2.224.jar:2.2.224]
at org.h2.value.Value.convertToEnum(Value.java:2311) ~[h2-2.2.224.jar:2.2.224]
at org.h2.value.Value.convertTo(Value.java:1195) ~[h2-2.2.224.jar:2.2.224]
at org.h2.value.Value.convertToArray(Value.java:2508) ~[h2-2.2.224.jar:2.2.224]
at org.h2.value.Value.convertTo(Value.java:1203) ~[h2-2.2.224.jar:2.2.224]
at org.h2.value.Value.convertForAssignTo(Value.java:1113) ~[h2-2.2.224.jar:2.2.224]
at org.h2.table.Column.validateConvertUpdateSequence(Column.java:369) ~[h2-2.2.224.jar:2.2.224]
at org.h2.table.Table.convertInsertRow(Table.java:936) ~[h2-2.2.224.jar:2.2.224]
at org.h2.command.dml.Insert.insertRows(Insert.java:167) ~[h2-2.2.224.jar:2.2.224]
at org.h2.command.dml.Insert.update(Insert.java:135) ~[h2-2.2.224.jar:2.2.224]
at org.h2.command.CommandContainer.executeUpdateWithGeneratedKeys(CommandContainer.java:242) ~[h2-2.2.224.jar:2.2.224]
at org.h2.command.CommandContainer.update(CommandContainer.java:163) ~[h2-2.2.224.jar:2.2.224]
at org.h2.command.Command.executeUpdate(Command.java:256) ~[h2-2.2.224.jar:2.2.224]
at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:216) ~[h2-2.2.224.jar:2.2.224]
at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:174) ~[h2-2.2.224.jar:2.2.224]
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) ~[HikariCP-5.1.0.jar:na]
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java) ~[HikariCP-5.1.0.jar:na]
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:194) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.id.insert.GetGeneratedKeysDelegate.performMutation(GetGeneratedKeysDelegate.java:116) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.engine.jdbc.mutation.internal.MutationExecutorSingleNonBatched.performNonBatchedOperations(MutationExecutorSingleNonBatched.java:47) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.execute(AbstractMutationExecutor.java:55) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.persister.entity.mutation.InsertCoordinatorStandard.doStaticInserts(InsertCoordinatorStandard.java:194) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.persister.entity.mutation.InsertCoordinatorStandard.coordinateInsert(InsertCoordinatorStandard.java:132) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.persister.entity.mutation.InsertCoordinatorStandard.insert(InsertCoordinatorStandard.java:95) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:85) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:670) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:291) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:272) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:322) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:391) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:305) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:224) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:137) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:175) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.event.internal.DefaultPersistEventListener.persist(DefaultPersistEventListener.java:93) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:77) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:54) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:757) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
a...
Das komische daran ist, wenn ich das Objekt mit Postman sende, dann funktioniert alles Problemlos:
Rich (BB-Code):
Configuration (row, JSON, application/json)
{
"id": null,
"puppyId": 27,
"name": "Welpe",
"color": "Braun",
"weight": 5.5,
"height": 30.0,
"image": "/assets/images/welps/maxxx.jpg",
"characteristic": ["Friendly", "Curious"],
"race": {
"id": null,
"race": "Haski"
},
"price": 450.99
}