[jboss-jira] [JBoss JIRA] (HIBERNATE-167) Map with Enum as key value generates two need unnecessary update statements

nimo stephan (Jira) issues at jboss.org
Mon Aug 5 06:12:01 EDT 2019


     [ https://issues.jboss.org/browse/HIBERNATE-167?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

nimo stephan updated HIBERNATE-167:
-----------------------------------
    Steps to Reproduce: 
1. create a Map with key as Enum and String as value
2. use an AttributeConverter for that Map
3. persist a new Entity having this Map as a property
4. look at the console: you will see two unnecessary update statements for this Map

  was:
1. create a Map with key as Enum and String as value
2. use a AttributeConverter for that Map
3. persist a new Entity having this Map as a property
4. look at the console: you will see two unnecessary update statements for this Map



> Map with Enum as key value generates two need unnecessary update statements
> ---------------------------------------------------------------------------
>
>                 Key: HIBERNATE-167
>                 URL: https://issues.jboss.org/browse/HIBERNATE-167
>             Project: Hibernate Integration
>          Issue Type: Bug
>         Environment: hibernate-core (v. 5.4.4.Final)
>            Reporter: nimo stephan
>            Assignee: Steve Ebersole
>            Priority: Major
>              Labels: hibernate
>
> Having this within an Entity class:
> {code:java}
> public class User {
> @Column(name = "test")
> private String test;
> // this makes trouble (but the taskConverter works as expected)
> // only the persisting makes two needless update statements each time a new User is created
> @Column(name = "tasks")
> @Convert(converter = TasksConverter.class)
> private Map<Task, String> tasks;
> }
> {code}
> and creating a new Entity
> {code:java}
> User user = new User();
> user.setName("test");
> // this generates two unnecessary updates:
> user.setTasks(Map.of(Task.TASK_START, "hello"));
> {code}
> creates at first the entity:
> {code:java}
> /* insert my.User
> 11:54:43,848 INFO  [stdout]         */ insert 
> 11:54:43,848 INFO  [stdout]         into
> 11:54:43,848 INFO  [stdout]             user
> 11:54:43,855 INFO  [stdout]             (test, tasks)
> 11:54:43,855 INFO  [stdout]             values
> 11:54:43,855 INFO  [stdout]             (?, ?)
> {code}
> *and produces afterwards within the same session two entity updates (which are needless):*
> {code:java}
> /* update
> 11:54:44,100 INFO  [stdout]         my.User*/ update
> 11:54:44,100 INFO  [stdout]             user 
> 11:54:44,100 INFO  [stdout]         set
> 11:54:44,100 INFO  [stdout]             tasks=? 
> 11:54:44,100 INFO  [stdout]         where
> 11:54:44,100 INFO  [stdout]             id_user=? 
> ...
> 11:54:44,157 INFO  [stdout]     /* update
> 11:54:44,157 INFO  [stdout]         my.User */ update
> 11:54:44,157 INFO  [stdout]             user 
> 11:54:44,157 INFO  [stdout]         set
> 11:54:44,157 INFO  [stdout]             tasks=? 
> 11:54:44,158 INFO  [stdout]         where
> 11:54:44,158 INFO  [stdout]             id_user=? 
> {code}
> *If I replace this:*
> @Column(name = "tasks")
> @Convert(converter = TasksConverter.class)
> private Map<Task, String> tasks;
> *with this (using string instead of enum as key):*
> {code:java}
> @Column(name = "tasks")
> @Convert(converter = TasksConverter.class)
> private Map<String, String> tasks;
> {code}
> then all works AND no two needless update statements are produces.



--
This message was sent by Atlassian Jira
(v7.12.1#712002)


More information about the jboss-jira mailing list