3

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:

  • User A via REST API
  • User B via SQL statement
  • User C via REST API

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?

4
  • 2
    Did you commited your insert? Commented Sep 18, 2018 at 15:44
  • Hmm didn't know there was a commit keyword in oracle :) Commented Sep 18, 2018 at 15:48
  • 1
    @MarmiteBomber COMMIT WORK; worked! Thank you! Commented Sep 18, 2018 at 15:51
  • Glead to be helpfull;) and yes, there is no autocommit=TRUE if you use the INSERT statement. Commented Sep 19, 2018 at 5:35

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.