the modifying can not be visible in the same transaction in spring data jpa,why i got null after modifying in...












0















show code first,here is my code,as below:



   public void saveTestTx() {
Lock lock = new Lock();
lock.setName("ABCDEFG");
lock.setDeviceId("22dfgdfgdftrtg");
lock.setCreateTime((new Date()));
Lock lock1 = lockDao.saveAndFlush(lock);
System.out.println("lock1 = " + lock1);
Lock lock2 = lockDao.findByDeviceId(lock.getDeviceId());
System.out.println("lock2 = " + lock2); // got null here
}


enter image description here(here is the screenshot)



i'm sure that the method 'saveTestTx()' is a completely transaction , because if i called print(22/0) ,it can be rolled back. i mean that the codes from line 192 to line 199 are in the a same transaction . from my java development experience, i think the lock2 is the result of lock1, i know that before printing the lock2,the transaction have not commited yet,but they are in a same transaction,the modifying in the same transaction would be visible ,so before comitting transaction,it could be selected from after called "saveAndFlush()" method, and the insert statement is printed at console,but in fact, why lock2 is printed null?



my transaction configration is as below:



@Configuration
public class TxConfig {
@Bean("txSource")
public TransactionAttributeSource transactionAttributeSource() {
NameMatchTransactionAttributeSource source = new NameMatchTransactionAttributeSource();
RuleBasedTransactionAttribute readOnlyTx = new RuleBasedTransactionAttribute();
readOnlyTx.setReadOnly(true);
readOnlyTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
RuleBasedTransactionAttribute requiredTx = new RuleBasedTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED,
Collections.singletonList(new RollbackRuleAttribute(Exception.class)));
int isolationLevel = requiredTx.getIsolationLevel();
// requiredTx.setTimeout(90);
Map<String, TransactionAttribute> txMap = new HashMap<>();
txMap.put("init*", requiredTx);
txMap.put("add*", requiredTx);
txMap.put("save*", requiredTx);
txMap.put("insert*", requiredTx);
txMap.put("create*", requiredTx);
txMap.put("persist*", requiredTx);
txMap.put("update*", requiredTx);
txMap.put("modify*", requiredTx);
txMap.put("merge*", requiredTx);
txMap.put("bind*", requiredTx);
txMap.put("delete*", requiredTx);
txMap.put("del*", requiredTx);
txMap.put("drop*", requiredTx);
txMap.put("remove*", requiredTx);
txMap.put("reset*", requiredTx);
txMap.put("cancel*", requiredTx);
txMap.put("login*", requiredTx);
txMap.put("*", readOnlyTx);
source.setNameMap(txMap);
return source;
}


@Bean
public AspectJExpressionPointcutAdvisor pointcutAdvisor(TransactionInterceptor txInterceptor) {
AspectJExpressionPointcutAdvisor pointcutAdvisor = new AspectJExpressionPointcutAdvisor();
pointcutAdvisor.setAdvice(txInterceptor);
// pointcutAdvisor.setExpression("execution (* com.hl..service..*.*(..))");
pointcutAdvisor.setExpression("execution (* com..service..*.*(..)) || execution (* com..dao..*.*(..))");
return pointcutAdvisor;
}

@Bean("txInterceptor")
TransactionInterceptor getTransactionInterceptor(PlatformTransactionManager tx) {
return new TransactionInterceptor(tx, transactionAttributeSource());
}

}


my entity code is as below:



@Data
@ToString(callSuper = true)
@Entity
@Table(name = "police_lock")
@SQLDelete(sql = "update lock set is_deleted = 1 where id = ?")
@Where(clause = "is_deleted = 0")
@DynamicInsert
@DynamicUpdate
public class Lock extends LongBaseEntity {
public static interface AddGroup {};
public static interface UpdateGroup {};

private static final long serialVersionUID = 1L;

public Lock() {
super();
}

public Lock(Long id) {
this.id = id;
}
public Lock(boolean isInit) {
super(isInit);
}
@NotBlank(groups = {AddGroup.class,UpdateGroup.class})
private String deviceId;

@NotBlank(groups = {AddGroup.class,UpdateGroup.class})
private String name;
}


my table is as below:



SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for police_lock
-- ----------------------------
DROP TABLE IF EXISTS `police_lock`;
CREATE TABLE `police_lock` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`device_id` varchar(36) NOT NULL COMMENT 'device_id',
`name` varchar(40) NOT NULL COMMENT 'name',
`create_time` datetime NOT NULL COMMENT 'create_time',
`is_deleted` bit(1) DEFAULT b'0' COMMENT 'is_deleted',
PRIMARY KEY (`id`),
UNIQUE KEY `device_id` (`device_id`)
) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=utf8mb4 COMMENT='lock';


the method findByDeviceId() is a spring data jpa interface method,just defining a method is enough.it's feature of spring data jpa, after called saveAndFlush() method,it send a sql like this:



Hibernate: insert into police_lock (create_time, is_deleted, device_id, name) values (?, ?, ?, ?)


and after the method excuted,the transaction was commited and the database generated the new record. of course it's not generated before the method was excuted.but my question is that:thouth it's not commited,the modifying shoud be saw by following codes in the same transaction be it was not commited. but mine was not.i don't know why.. Am i missing something here?



my code is under spring boot,spring data jpa,mysql.










share|improve this question

























  • What's the code of the entity? What's the definition of the underlying table? What's the code of findByDeviceId? What are the SQL statements being executed? What do you see in the database after this method is executed?

    – JB Nizet
    Nov 23 '18 at 18:08













  • Something's fishy: your table doesn't have any is_deleted column, yet the SQL statement inserts a value in it. Have you checked that this value is 0? What is the SQL generated by the findByDeviceId() execution?

    – JB Nizet
    Nov 24 '18 at 7:22











  • thank's for your reply very much, of couse my table has such a column 'is_deleted', and i'm sure it's 0,because i set it 0 as a default value. to paste code here,i deleted some not key columns, now i updated to add it now. not only this table,but also all of my tables have the same question, and no exceptions are thrown,i guess that there may be something key point or configration i missed?

    – William
    Nov 24 '18 at 8:24
















0















show code first,here is my code,as below:



   public void saveTestTx() {
Lock lock = new Lock();
lock.setName("ABCDEFG");
lock.setDeviceId("22dfgdfgdftrtg");
lock.setCreateTime((new Date()));
Lock lock1 = lockDao.saveAndFlush(lock);
System.out.println("lock1 = " + lock1);
Lock lock2 = lockDao.findByDeviceId(lock.getDeviceId());
System.out.println("lock2 = " + lock2); // got null here
}


enter image description here(here is the screenshot)



i'm sure that the method 'saveTestTx()' is a completely transaction , because if i called print(22/0) ,it can be rolled back. i mean that the codes from line 192 to line 199 are in the a same transaction . from my java development experience, i think the lock2 is the result of lock1, i know that before printing the lock2,the transaction have not commited yet,but they are in a same transaction,the modifying in the same transaction would be visible ,so before comitting transaction,it could be selected from after called "saveAndFlush()" method, and the insert statement is printed at console,but in fact, why lock2 is printed null?



my transaction configration is as below:



@Configuration
public class TxConfig {
@Bean("txSource")
public TransactionAttributeSource transactionAttributeSource() {
NameMatchTransactionAttributeSource source = new NameMatchTransactionAttributeSource();
RuleBasedTransactionAttribute readOnlyTx = new RuleBasedTransactionAttribute();
readOnlyTx.setReadOnly(true);
readOnlyTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
RuleBasedTransactionAttribute requiredTx = new RuleBasedTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED,
Collections.singletonList(new RollbackRuleAttribute(Exception.class)));
int isolationLevel = requiredTx.getIsolationLevel();
// requiredTx.setTimeout(90);
Map<String, TransactionAttribute> txMap = new HashMap<>();
txMap.put("init*", requiredTx);
txMap.put("add*", requiredTx);
txMap.put("save*", requiredTx);
txMap.put("insert*", requiredTx);
txMap.put("create*", requiredTx);
txMap.put("persist*", requiredTx);
txMap.put("update*", requiredTx);
txMap.put("modify*", requiredTx);
txMap.put("merge*", requiredTx);
txMap.put("bind*", requiredTx);
txMap.put("delete*", requiredTx);
txMap.put("del*", requiredTx);
txMap.put("drop*", requiredTx);
txMap.put("remove*", requiredTx);
txMap.put("reset*", requiredTx);
txMap.put("cancel*", requiredTx);
txMap.put("login*", requiredTx);
txMap.put("*", readOnlyTx);
source.setNameMap(txMap);
return source;
}


@Bean
public AspectJExpressionPointcutAdvisor pointcutAdvisor(TransactionInterceptor txInterceptor) {
AspectJExpressionPointcutAdvisor pointcutAdvisor = new AspectJExpressionPointcutAdvisor();
pointcutAdvisor.setAdvice(txInterceptor);
// pointcutAdvisor.setExpression("execution (* com.hl..service..*.*(..))");
pointcutAdvisor.setExpression("execution (* com..service..*.*(..)) || execution (* com..dao..*.*(..))");
return pointcutAdvisor;
}

@Bean("txInterceptor")
TransactionInterceptor getTransactionInterceptor(PlatformTransactionManager tx) {
return new TransactionInterceptor(tx, transactionAttributeSource());
}

}


my entity code is as below:



@Data
@ToString(callSuper = true)
@Entity
@Table(name = "police_lock")
@SQLDelete(sql = "update lock set is_deleted = 1 where id = ?")
@Where(clause = "is_deleted = 0")
@DynamicInsert
@DynamicUpdate
public class Lock extends LongBaseEntity {
public static interface AddGroup {};
public static interface UpdateGroup {};

private static final long serialVersionUID = 1L;

public Lock() {
super();
}

public Lock(Long id) {
this.id = id;
}
public Lock(boolean isInit) {
super(isInit);
}
@NotBlank(groups = {AddGroup.class,UpdateGroup.class})
private String deviceId;

@NotBlank(groups = {AddGroup.class,UpdateGroup.class})
private String name;
}


my table is as below:



SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for police_lock
-- ----------------------------
DROP TABLE IF EXISTS `police_lock`;
CREATE TABLE `police_lock` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`device_id` varchar(36) NOT NULL COMMENT 'device_id',
`name` varchar(40) NOT NULL COMMENT 'name',
`create_time` datetime NOT NULL COMMENT 'create_time',
`is_deleted` bit(1) DEFAULT b'0' COMMENT 'is_deleted',
PRIMARY KEY (`id`),
UNIQUE KEY `device_id` (`device_id`)
) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=utf8mb4 COMMENT='lock';


the method findByDeviceId() is a spring data jpa interface method,just defining a method is enough.it's feature of spring data jpa, after called saveAndFlush() method,it send a sql like this:



Hibernate: insert into police_lock (create_time, is_deleted, device_id, name) values (?, ?, ?, ?)


and after the method excuted,the transaction was commited and the database generated the new record. of course it's not generated before the method was excuted.but my question is that:thouth it's not commited,the modifying shoud be saw by following codes in the same transaction be it was not commited. but mine was not.i don't know why.. Am i missing something here?



my code is under spring boot,spring data jpa,mysql.










share|improve this question

























  • What's the code of the entity? What's the definition of the underlying table? What's the code of findByDeviceId? What are the SQL statements being executed? What do you see in the database after this method is executed?

    – JB Nizet
    Nov 23 '18 at 18:08













  • Something's fishy: your table doesn't have any is_deleted column, yet the SQL statement inserts a value in it. Have you checked that this value is 0? What is the SQL generated by the findByDeviceId() execution?

    – JB Nizet
    Nov 24 '18 at 7:22











  • thank's for your reply very much, of couse my table has such a column 'is_deleted', and i'm sure it's 0,because i set it 0 as a default value. to paste code here,i deleted some not key columns, now i updated to add it now. not only this table,but also all of my tables have the same question, and no exceptions are thrown,i guess that there may be something key point or configration i missed?

    – William
    Nov 24 '18 at 8:24














0












0








0








show code first,here is my code,as below:



   public void saveTestTx() {
Lock lock = new Lock();
lock.setName("ABCDEFG");
lock.setDeviceId("22dfgdfgdftrtg");
lock.setCreateTime((new Date()));
Lock lock1 = lockDao.saveAndFlush(lock);
System.out.println("lock1 = " + lock1);
Lock lock2 = lockDao.findByDeviceId(lock.getDeviceId());
System.out.println("lock2 = " + lock2); // got null here
}


enter image description here(here is the screenshot)



i'm sure that the method 'saveTestTx()' is a completely transaction , because if i called print(22/0) ,it can be rolled back. i mean that the codes from line 192 to line 199 are in the a same transaction . from my java development experience, i think the lock2 is the result of lock1, i know that before printing the lock2,the transaction have not commited yet,but they are in a same transaction,the modifying in the same transaction would be visible ,so before comitting transaction,it could be selected from after called "saveAndFlush()" method, and the insert statement is printed at console,but in fact, why lock2 is printed null?



my transaction configration is as below:



@Configuration
public class TxConfig {
@Bean("txSource")
public TransactionAttributeSource transactionAttributeSource() {
NameMatchTransactionAttributeSource source = new NameMatchTransactionAttributeSource();
RuleBasedTransactionAttribute readOnlyTx = new RuleBasedTransactionAttribute();
readOnlyTx.setReadOnly(true);
readOnlyTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
RuleBasedTransactionAttribute requiredTx = new RuleBasedTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED,
Collections.singletonList(new RollbackRuleAttribute(Exception.class)));
int isolationLevel = requiredTx.getIsolationLevel();
// requiredTx.setTimeout(90);
Map<String, TransactionAttribute> txMap = new HashMap<>();
txMap.put("init*", requiredTx);
txMap.put("add*", requiredTx);
txMap.put("save*", requiredTx);
txMap.put("insert*", requiredTx);
txMap.put("create*", requiredTx);
txMap.put("persist*", requiredTx);
txMap.put("update*", requiredTx);
txMap.put("modify*", requiredTx);
txMap.put("merge*", requiredTx);
txMap.put("bind*", requiredTx);
txMap.put("delete*", requiredTx);
txMap.put("del*", requiredTx);
txMap.put("drop*", requiredTx);
txMap.put("remove*", requiredTx);
txMap.put("reset*", requiredTx);
txMap.put("cancel*", requiredTx);
txMap.put("login*", requiredTx);
txMap.put("*", readOnlyTx);
source.setNameMap(txMap);
return source;
}


@Bean
public AspectJExpressionPointcutAdvisor pointcutAdvisor(TransactionInterceptor txInterceptor) {
AspectJExpressionPointcutAdvisor pointcutAdvisor = new AspectJExpressionPointcutAdvisor();
pointcutAdvisor.setAdvice(txInterceptor);
// pointcutAdvisor.setExpression("execution (* com.hl..service..*.*(..))");
pointcutAdvisor.setExpression("execution (* com..service..*.*(..)) || execution (* com..dao..*.*(..))");
return pointcutAdvisor;
}

@Bean("txInterceptor")
TransactionInterceptor getTransactionInterceptor(PlatformTransactionManager tx) {
return new TransactionInterceptor(tx, transactionAttributeSource());
}

}


my entity code is as below:



@Data
@ToString(callSuper = true)
@Entity
@Table(name = "police_lock")
@SQLDelete(sql = "update lock set is_deleted = 1 where id = ?")
@Where(clause = "is_deleted = 0")
@DynamicInsert
@DynamicUpdate
public class Lock extends LongBaseEntity {
public static interface AddGroup {};
public static interface UpdateGroup {};

private static final long serialVersionUID = 1L;

public Lock() {
super();
}

public Lock(Long id) {
this.id = id;
}
public Lock(boolean isInit) {
super(isInit);
}
@NotBlank(groups = {AddGroup.class,UpdateGroup.class})
private String deviceId;

@NotBlank(groups = {AddGroup.class,UpdateGroup.class})
private String name;
}


my table is as below:



SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for police_lock
-- ----------------------------
DROP TABLE IF EXISTS `police_lock`;
CREATE TABLE `police_lock` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`device_id` varchar(36) NOT NULL COMMENT 'device_id',
`name` varchar(40) NOT NULL COMMENT 'name',
`create_time` datetime NOT NULL COMMENT 'create_time',
`is_deleted` bit(1) DEFAULT b'0' COMMENT 'is_deleted',
PRIMARY KEY (`id`),
UNIQUE KEY `device_id` (`device_id`)
) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=utf8mb4 COMMENT='lock';


the method findByDeviceId() is a spring data jpa interface method,just defining a method is enough.it's feature of spring data jpa, after called saveAndFlush() method,it send a sql like this:



Hibernate: insert into police_lock (create_time, is_deleted, device_id, name) values (?, ?, ?, ?)


and after the method excuted,the transaction was commited and the database generated the new record. of course it's not generated before the method was excuted.but my question is that:thouth it's not commited,the modifying shoud be saw by following codes in the same transaction be it was not commited. but mine was not.i don't know why.. Am i missing something here?



my code is under spring boot,spring data jpa,mysql.










share|improve this question
















show code first,here is my code,as below:



   public void saveTestTx() {
Lock lock = new Lock();
lock.setName("ABCDEFG");
lock.setDeviceId("22dfgdfgdftrtg");
lock.setCreateTime((new Date()));
Lock lock1 = lockDao.saveAndFlush(lock);
System.out.println("lock1 = " + lock1);
Lock lock2 = lockDao.findByDeviceId(lock.getDeviceId());
System.out.println("lock2 = " + lock2); // got null here
}


enter image description here(here is the screenshot)



i'm sure that the method 'saveTestTx()' is a completely transaction , because if i called print(22/0) ,it can be rolled back. i mean that the codes from line 192 to line 199 are in the a same transaction . from my java development experience, i think the lock2 is the result of lock1, i know that before printing the lock2,the transaction have not commited yet,but they are in a same transaction,the modifying in the same transaction would be visible ,so before comitting transaction,it could be selected from after called "saveAndFlush()" method, and the insert statement is printed at console,but in fact, why lock2 is printed null?



my transaction configration is as below:



@Configuration
public class TxConfig {
@Bean("txSource")
public TransactionAttributeSource transactionAttributeSource() {
NameMatchTransactionAttributeSource source = new NameMatchTransactionAttributeSource();
RuleBasedTransactionAttribute readOnlyTx = new RuleBasedTransactionAttribute();
readOnlyTx.setReadOnly(true);
readOnlyTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
RuleBasedTransactionAttribute requiredTx = new RuleBasedTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED,
Collections.singletonList(new RollbackRuleAttribute(Exception.class)));
int isolationLevel = requiredTx.getIsolationLevel();
// requiredTx.setTimeout(90);
Map<String, TransactionAttribute> txMap = new HashMap<>();
txMap.put("init*", requiredTx);
txMap.put("add*", requiredTx);
txMap.put("save*", requiredTx);
txMap.put("insert*", requiredTx);
txMap.put("create*", requiredTx);
txMap.put("persist*", requiredTx);
txMap.put("update*", requiredTx);
txMap.put("modify*", requiredTx);
txMap.put("merge*", requiredTx);
txMap.put("bind*", requiredTx);
txMap.put("delete*", requiredTx);
txMap.put("del*", requiredTx);
txMap.put("drop*", requiredTx);
txMap.put("remove*", requiredTx);
txMap.put("reset*", requiredTx);
txMap.put("cancel*", requiredTx);
txMap.put("login*", requiredTx);
txMap.put("*", readOnlyTx);
source.setNameMap(txMap);
return source;
}


@Bean
public AspectJExpressionPointcutAdvisor pointcutAdvisor(TransactionInterceptor txInterceptor) {
AspectJExpressionPointcutAdvisor pointcutAdvisor = new AspectJExpressionPointcutAdvisor();
pointcutAdvisor.setAdvice(txInterceptor);
// pointcutAdvisor.setExpression("execution (* com.hl..service..*.*(..))");
pointcutAdvisor.setExpression("execution (* com..service..*.*(..)) || execution (* com..dao..*.*(..))");
return pointcutAdvisor;
}

@Bean("txInterceptor")
TransactionInterceptor getTransactionInterceptor(PlatformTransactionManager tx) {
return new TransactionInterceptor(tx, transactionAttributeSource());
}

}


my entity code is as below:



@Data
@ToString(callSuper = true)
@Entity
@Table(name = "police_lock")
@SQLDelete(sql = "update lock set is_deleted = 1 where id = ?")
@Where(clause = "is_deleted = 0")
@DynamicInsert
@DynamicUpdate
public class Lock extends LongBaseEntity {
public static interface AddGroup {};
public static interface UpdateGroup {};

private static final long serialVersionUID = 1L;

public Lock() {
super();
}

public Lock(Long id) {
this.id = id;
}
public Lock(boolean isInit) {
super(isInit);
}
@NotBlank(groups = {AddGroup.class,UpdateGroup.class})
private String deviceId;

@NotBlank(groups = {AddGroup.class,UpdateGroup.class})
private String name;
}


my table is as below:



SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for police_lock
-- ----------------------------
DROP TABLE IF EXISTS `police_lock`;
CREATE TABLE `police_lock` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`device_id` varchar(36) NOT NULL COMMENT 'device_id',
`name` varchar(40) NOT NULL COMMENT 'name',
`create_time` datetime NOT NULL COMMENT 'create_time',
`is_deleted` bit(1) DEFAULT b'0' COMMENT 'is_deleted',
PRIMARY KEY (`id`),
UNIQUE KEY `device_id` (`device_id`)
) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=utf8mb4 COMMENT='lock';


the method findByDeviceId() is a spring data jpa interface method,just defining a method is enough.it's feature of spring data jpa, after called saveAndFlush() method,it send a sql like this:



Hibernate: insert into police_lock (create_time, is_deleted, device_id, name) values (?, ?, ?, ?)


and after the method excuted,the transaction was commited and the database generated the new record. of course it's not generated before the method was excuted.but my question is that:thouth it's not commited,the modifying shoud be saw by following codes in the same transaction be it was not commited. but mine was not.i don't know why.. Am i missing something here?



my code is under spring boot,spring data jpa,mysql.







java spring transactions spring-data-jpa






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 8:16







William

















asked Nov 23 '18 at 16:02









WilliamWilliam

11




11













  • What's the code of the entity? What's the definition of the underlying table? What's the code of findByDeviceId? What are the SQL statements being executed? What do you see in the database after this method is executed?

    – JB Nizet
    Nov 23 '18 at 18:08













  • Something's fishy: your table doesn't have any is_deleted column, yet the SQL statement inserts a value in it. Have you checked that this value is 0? What is the SQL generated by the findByDeviceId() execution?

    – JB Nizet
    Nov 24 '18 at 7:22











  • thank's for your reply very much, of couse my table has such a column 'is_deleted', and i'm sure it's 0,because i set it 0 as a default value. to paste code here,i deleted some not key columns, now i updated to add it now. not only this table,but also all of my tables have the same question, and no exceptions are thrown,i guess that there may be something key point or configration i missed?

    – William
    Nov 24 '18 at 8:24



















  • What's the code of the entity? What's the definition of the underlying table? What's the code of findByDeviceId? What are the SQL statements being executed? What do you see in the database after this method is executed?

    – JB Nizet
    Nov 23 '18 at 18:08













  • Something's fishy: your table doesn't have any is_deleted column, yet the SQL statement inserts a value in it. Have you checked that this value is 0? What is the SQL generated by the findByDeviceId() execution?

    – JB Nizet
    Nov 24 '18 at 7:22











  • thank's for your reply very much, of couse my table has such a column 'is_deleted', and i'm sure it's 0,because i set it 0 as a default value. to paste code here,i deleted some not key columns, now i updated to add it now. not only this table,but also all of my tables have the same question, and no exceptions are thrown,i guess that there may be something key point or configration i missed?

    – William
    Nov 24 '18 at 8:24

















What's the code of the entity? What's the definition of the underlying table? What's the code of findByDeviceId? What are the SQL statements being executed? What do you see in the database after this method is executed?

– JB Nizet
Nov 23 '18 at 18:08







What's the code of the entity? What's the definition of the underlying table? What's the code of findByDeviceId? What are the SQL statements being executed? What do you see in the database after this method is executed?

– JB Nizet
Nov 23 '18 at 18:08















Something's fishy: your table doesn't have any is_deleted column, yet the SQL statement inserts a value in it. Have you checked that this value is 0? What is the SQL generated by the findByDeviceId() execution?

– JB Nizet
Nov 24 '18 at 7:22





Something's fishy: your table doesn't have any is_deleted column, yet the SQL statement inserts a value in it. Have you checked that this value is 0? What is the SQL generated by the findByDeviceId() execution?

– JB Nizet
Nov 24 '18 at 7:22













thank's for your reply very much, of couse my table has such a column 'is_deleted', and i'm sure it's 0,because i set it 0 as a default value. to paste code here,i deleted some not key columns, now i updated to add it now. not only this table,but also all of my tables have the same question, and no exceptions are thrown,i guess that there may be something key point or configration i missed?

– William
Nov 24 '18 at 8:24





thank's for your reply very much, of couse my table has such a column 'is_deleted', and i'm sure it's 0,because i set it 0 as a default value. to paste code here,i deleted some not key columns, now i updated to add it now. not only this table,but also all of my tables have the same question, and no exceptions are thrown,i guess that there may be something key point or configration i missed?

– William
Nov 24 '18 at 8:24












1 Answer
1






active

oldest

votes


















0














i fixed it now, there is something wrong with my transaction configration,i modified it like as below:



@Configuration
public class TxConfig2 {
@Autowired
private PlatformTransactionManager transactionManager;

@Bean(name = "txAdvice")
public TransactionInterceptor getAdvisor() throws Exception {
System.out.println("transactionManager = " + transactionManager);
Properties properties = new Properties();
properties.setProperty("init*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("add*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("insert*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("create*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("persist*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("update*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("modify*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("merge*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("bind*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("del*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("drop*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("remove*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("reset*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("cancel*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("login*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("save*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("update*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("delete*", "PROPAGATION_REQUIRED,-Exception");
properties.setProperty("*", "PROPAGATION_REQUIRED,-Exception,readOnly");
TransactionInterceptor tsi = new TransactionInterceptor(transactionManager, properties);
return tsi;
}
@Bean
public BeanNameAutoProxyCreator txProxy() {
BeanNameAutoProxyCreator creator = new BeanNameAutoProxyCreator();
creator.setInterceptorNames("txAdvice");
creator.setBeanNames("*Service","*Dao");
creator.setProxyTargetClass(true);
return creator;
}
}


then it works fine!!!






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449779%2fthe-modifying-can-not-be-visible-in-the-same-transaction-in-spring-data-jpa-why%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    i fixed it now, there is something wrong with my transaction configration,i modified it like as below:



    @Configuration
    public class TxConfig2 {
    @Autowired
    private PlatformTransactionManager transactionManager;

    @Bean(name = "txAdvice")
    public TransactionInterceptor getAdvisor() throws Exception {
    System.out.println("transactionManager = " + transactionManager);
    Properties properties = new Properties();
    properties.setProperty("init*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("add*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("insert*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("create*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("persist*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("update*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("modify*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("merge*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("bind*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("del*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("drop*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("remove*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("reset*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("cancel*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("login*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("save*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("update*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("delete*", "PROPAGATION_REQUIRED,-Exception");
    properties.setProperty("*", "PROPAGATION_REQUIRED,-Exception,readOnly");
    TransactionInterceptor tsi = new TransactionInterceptor(transactionManager, properties);
    return tsi;
    }
    @Bean
    public BeanNameAutoProxyCreator txProxy() {
    BeanNameAutoProxyCreator creator = new BeanNameAutoProxyCreator();
    creator.setInterceptorNames("txAdvice");
    creator.setBeanNames("*Service","*Dao");
    creator.setProxyTargetClass(true);
    return creator;
    }
    }


    then it works fine!!!






    share|improve this answer




























      0














      i fixed it now, there is something wrong with my transaction configration,i modified it like as below:



      @Configuration
      public class TxConfig2 {
      @Autowired
      private PlatformTransactionManager transactionManager;

      @Bean(name = "txAdvice")
      public TransactionInterceptor getAdvisor() throws Exception {
      System.out.println("transactionManager = " + transactionManager);
      Properties properties = new Properties();
      properties.setProperty("init*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("add*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("insert*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("create*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("persist*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("update*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("modify*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("merge*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("bind*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("del*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("drop*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("remove*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("reset*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("cancel*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("login*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("save*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("update*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("delete*", "PROPAGATION_REQUIRED,-Exception");
      properties.setProperty("*", "PROPAGATION_REQUIRED,-Exception,readOnly");
      TransactionInterceptor tsi = new TransactionInterceptor(transactionManager, properties);
      return tsi;
      }
      @Bean
      public BeanNameAutoProxyCreator txProxy() {
      BeanNameAutoProxyCreator creator = new BeanNameAutoProxyCreator();
      creator.setInterceptorNames("txAdvice");
      creator.setBeanNames("*Service","*Dao");
      creator.setProxyTargetClass(true);
      return creator;
      }
      }


      then it works fine!!!






      share|improve this answer


























        0












        0








        0







        i fixed it now, there is something wrong with my transaction configration,i modified it like as below:



        @Configuration
        public class TxConfig2 {
        @Autowired
        private PlatformTransactionManager transactionManager;

        @Bean(name = "txAdvice")
        public TransactionInterceptor getAdvisor() throws Exception {
        System.out.println("transactionManager = " + transactionManager);
        Properties properties = new Properties();
        properties.setProperty("init*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("add*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("insert*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("create*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("persist*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("update*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("modify*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("merge*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("bind*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("del*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("drop*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("remove*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("reset*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("cancel*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("login*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("save*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("update*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("delete*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("*", "PROPAGATION_REQUIRED,-Exception,readOnly");
        TransactionInterceptor tsi = new TransactionInterceptor(transactionManager, properties);
        return tsi;
        }
        @Bean
        public BeanNameAutoProxyCreator txProxy() {
        BeanNameAutoProxyCreator creator = new BeanNameAutoProxyCreator();
        creator.setInterceptorNames("txAdvice");
        creator.setBeanNames("*Service","*Dao");
        creator.setProxyTargetClass(true);
        return creator;
        }
        }


        then it works fine!!!






        share|improve this answer













        i fixed it now, there is something wrong with my transaction configration,i modified it like as below:



        @Configuration
        public class TxConfig2 {
        @Autowired
        private PlatformTransactionManager transactionManager;

        @Bean(name = "txAdvice")
        public TransactionInterceptor getAdvisor() throws Exception {
        System.out.println("transactionManager = " + transactionManager);
        Properties properties = new Properties();
        properties.setProperty("init*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("add*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("insert*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("create*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("persist*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("update*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("modify*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("merge*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("bind*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("del*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("drop*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("remove*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("reset*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("cancel*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("login*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("save*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("update*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("delete*", "PROPAGATION_REQUIRED,-Exception");
        properties.setProperty("*", "PROPAGATION_REQUIRED,-Exception,readOnly");
        TransactionInterceptor tsi = new TransactionInterceptor(transactionManager, properties);
        return tsi;
        }
        @Bean
        public BeanNameAutoProxyCreator txProxy() {
        BeanNameAutoProxyCreator creator = new BeanNameAutoProxyCreator();
        creator.setInterceptorNames("txAdvice");
        creator.setBeanNames("*Service","*Dao");
        creator.setProxyTargetClass(true);
        return creator;
        }
        }


        then it works fine!!!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 13:19









        WilliamWilliam

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449779%2fthe-modifying-can-not-be-visible-in-the-same-transaction-in-spring-data-jpa-why%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...