Snæbjørn
Snæbjørn

Reputation: 10792

Hibernate doesn't return manually INSERTed rows

I'm having an issue with my jpa repository doesn't return rows that I've manually inserted into the database (Oracle) via good old SQL

Insert into SYSTEM.USER (ID,CREDENTIALS,ISADMIN) values (USERSEQ.nextval,'foo',1);

My Jpa Repository

@RepositoryRestResource
public interface UserRepository extends JpaRepository<User, Long> {}

User entity

@Data
@Entity
public class User {
  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idgen")
  @SequenceGenerator(initialValue = 1, allocationSize = 1, name = "idgen", sequenceName = "userseq")
  private Long id;

  @NotNull
  private String credentials;

  private boolean isAdmin;
}

The super weird thing is that entries that I've inserted via the REST interface works!

So if I create:

The result of GET /api/users is A, C

After pulling out all my hair. I think I've narrowed it down to the Flashback feature Oracle has. As only A and C has entries in the Flashback. So Hibernate must do some magic behind the scene.

So my question is. How do I insert a row using SQL so it get a flashback entry also.

If the flashback thing isn't the problem. How do I make Hibernate return all the rows then?

Upvotes: 3

Views: 700

Answers (1)

Ritunjay kumar
Ritunjay kumar

Reputation: 467

while you are executing the SQL query in Oracle Sql Developer that time it is working own session. and JPA is working own session. i.e. JPA is not able to access the SQL query's records.

solution

Insert into SYSTEM.USER (ID,CREDENTIALS,ISADMIN) values (USERSEQ.nextval,'foo',1);

after that just fire the COMMIT command in Oracle Sql Developer.

it is working for me.

Upvotes: 1

Related Questions