JPA commit() row skiped after persist()












-1















I'm try to add a new entity on my database, but everytime I try the commit row is skiped after the persist().



public T salvar(T t) {
EntityManager em = daoHelper.getEM();
try {
em.getTransaction().begin();
if (t.getId() == null) {
em.persist(t);
em.getTransaction().commit();
}
} catch (Exception e) {
} finally {
em.close();
}
return t;
}


I don't know what is wrong, because the object t is complete.



Edit 1: These are my entity atributes



private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "Id")
private Integer id;
@Column(name = "idItem")
private Integer idItem;
@Column(name = "pedidoData")
@Temporal(TemporalType.DATE)
private Date pedidoData;
@Size(max = 9)
@Column(name = "pedidoEnderecoCep")
private String pedidoEnderecoCep;
@Column(name = "pedidoEnderecoNumero")
private Integer pedidoEnderecoNumero;
@Size(max = 85)
@Column(name = "pedidoEnderecoBairro")
private String pedidoEnderecoBairro;


And this is the object that I'm trying to add:



enter image description here










share|improve this question

























  • It only happens with one entity. I just tested and the same code worked with another entity

    – Leandro Souza
    Nov 22 '18 at 4:10











  • Can you share the sequence of inputs you are sending to this method?

    – codeLover
    Nov 22 '18 at 4:15











  • @codeLover Sure. I edited the question with more information

    – Leandro Souza
    Nov 22 '18 at 4:25











  • If commit is "skipped" then a Throwable is thrown. End of. So debug why an exception is thrown. Basic java.

    – Billy Frost
    Nov 22 '18 at 10:50
















-1















I'm try to add a new entity on my database, but everytime I try the commit row is skiped after the persist().



public T salvar(T t) {
EntityManager em = daoHelper.getEM();
try {
em.getTransaction().begin();
if (t.getId() == null) {
em.persist(t);
em.getTransaction().commit();
}
} catch (Exception e) {
} finally {
em.close();
}
return t;
}


I don't know what is wrong, because the object t is complete.



Edit 1: These are my entity atributes



private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "Id")
private Integer id;
@Column(name = "idItem")
private Integer idItem;
@Column(name = "pedidoData")
@Temporal(TemporalType.DATE)
private Date pedidoData;
@Size(max = 9)
@Column(name = "pedidoEnderecoCep")
private String pedidoEnderecoCep;
@Column(name = "pedidoEnderecoNumero")
private Integer pedidoEnderecoNumero;
@Size(max = 85)
@Column(name = "pedidoEnderecoBairro")
private String pedidoEnderecoBairro;


And this is the object that I'm trying to add:



enter image description here










share|improve this question

























  • It only happens with one entity. I just tested and the same code worked with another entity

    – Leandro Souza
    Nov 22 '18 at 4:10











  • Can you share the sequence of inputs you are sending to this method?

    – codeLover
    Nov 22 '18 at 4:15











  • @codeLover Sure. I edited the question with more information

    – Leandro Souza
    Nov 22 '18 at 4:25











  • If commit is "skipped" then a Throwable is thrown. End of. So debug why an exception is thrown. Basic java.

    – Billy Frost
    Nov 22 '18 at 10:50














-1












-1








-1








I'm try to add a new entity on my database, but everytime I try the commit row is skiped after the persist().



public T salvar(T t) {
EntityManager em = daoHelper.getEM();
try {
em.getTransaction().begin();
if (t.getId() == null) {
em.persist(t);
em.getTransaction().commit();
}
} catch (Exception e) {
} finally {
em.close();
}
return t;
}


I don't know what is wrong, because the object t is complete.



Edit 1: These are my entity atributes



private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "Id")
private Integer id;
@Column(name = "idItem")
private Integer idItem;
@Column(name = "pedidoData")
@Temporal(TemporalType.DATE)
private Date pedidoData;
@Size(max = 9)
@Column(name = "pedidoEnderecoCep")
private String pedidoEnderecoCep;
@Column(name = "pedidoEnderecoNumero")
private Integer pedidoEnderecoNumero;
@Size(max = 85)
@Column(name = "pedidoEnderecoBairro")
private String pedidoEnderecoBairro;


And this is the object that I'm trying to add:



enter image description here










share|improve this question
















I'm try to add a new entity on my database, but everytime I try the commit row is skiped after the persist().



public T salvar(T t) {
EntityManager em = daoHelper.getEM();
try {
em.getTransaction().begin();
if (t.getId() == null) {
em.persist(t);
em.getTransaction().commit();
}
} catch (Exception e) {
} finally {
em.close();
}
return t;
}


I don't know what is wrong, because the object t is complete.



Edit 1: These are my entity atributes



private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "Id")
private Integer id;
@Column(name = "idItem")
private Integer idItem;
@Column(name = "pedidoData")
@Temporal(TemporalType.DATE)
private Date pedidoData;
@Size(max = 9)
@Column(name = "pedidoEnderecoCep")
private String pedidoEnderecoCep;
@Column(name = "pedidoEnderecoNumero")
private Integer pedidoEnderecoNumero;
@Size(max = 85)
@Column(name = "pedidoEnderecoBairro")
private String pedidoEnderecoBairro;


And this is the object that I'm trying to add:



enter image description here







java jpa






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 4:24







Leandro Souza

















asked Nov 22 '18 at 4:07









Leandro SouzaLeandro Souza

165




165













  • It only happens with one entity. I just tested and the same code worked with another entity

    – Leandro Souza
    Nov 22 '18 at 4:10











  • Can you share the sequence of inputs you are sending to this method?

    – codeLover
    Nov 22 '18 at 4:15











  • @codeLover Sure. I edited the question with more information

    – Leandro Souza
    Nov 22 '18 at 4:25











  • If commit is "skipped" then a Throwable is thrown. End of. So debug why an exception is thrown. Basic java.

    – Billy Frost
    Nov 22 '18 at 10:50



















  • It only happens with one entity. I just tested and the same code worked with another entity

    – Leandro Souza
    Nov 22 '18 at 4:10











  • Can you share the sequence of inputs you are sending to this method?

    – codeLover
    Nov 22 '18 at 4:15











  • @codeLover Sure. I edited the question with more information

    – Leandro Souza
    Nov 22 '18 at 4:25











  • If commit is "skipped" then a Throwable is thrown. End of. So debug why an exception is thrown. Basic java.

    – Billy Frost
    Nov 22 '18 at 10:50

















It only happens with one entity. I just tested and the same code worked with another entity

– Leandro Souza
Nov 22 '18 at 4:10





It only happens with one entity. I just tested and the same code worked with another entity

– Leandro Souza
Nov 22 '18 at 4:10













Can you share the sequence of inputs you are sending to this method?

– codeLover
Nov 22 '18 at 4:15





Can you share the sequence of inputs you are sending to this method?

– codeLover
Nov 22 '18 at 4:15













@codeLover Sure. I edited the question with more information

– Leandro Souza
Nov 22 '18 at 4:25





@codeLover Sure. I edited the question with more information

– Leandro Souza
Nov 22 '18 at 4:25













If commit is "skipped" then a Throwable is thrown. End of. So debug why an exception is thrown. Basic java.

– Billy Frost
Nov 22 '18 at 10:50





If commit is "skipped" then a Throwable is thrown. End of. So debug why an exception is thrown. Basic java.

– Billy Frost
Nov 22 '18 at 10:50












1 Answer
1






active

oldest

votes


















0














On a higher level, it seems the issue is because of the place you have kept your commit statement. You have kept it inside the if condition, so the commit happens only when the if condition is satisfied. For instance, in the sample input data shared by you id is not null, therefore, if condition is not satisfied, thus, commit won't take place, on the contrary if you will send entity with null id, commit will take place. You should move the commit statement outside the if block as:



 if (t.getId() == null) {
em.persist(t);
}
em.getTransaction().commit();





share|improve this answer
























  • The commit() row still been skipped

    – Leandro Souza
    Nov 22 '18 at 4:38











  • Can you explain what exactly you mean by " commit() row still been skipped "

    – codeLover
    Nov 22 '18 at 4:41











  • When I get to persist() row and click to move to the next row it goes directly to em.close() on debug mode. It's like em.getTransaction().commit(); doesn't exist.

    – Leandro Souza
    Nov 22 '18 at 4:52











  • you mean a Throwable is thrown. So DEBUG YOUR CODE and look at what Throwable is thrown!

    – Billy Frost
    Nov 22 '18 at 10:02











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%2f53423750%2fjpa-commit-row-skiped-after-persist%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














On a higher level, it seems the issue is because of the place you have kept your commit statement. You have kept it inside the if condition, so the commit happens only when the if condition is satisfied. For instance, in the sample input data shared by you id is not null, therefore, if condition is not satisfied, thus, commit won't take place, on the contrary if you will send entity with null id, commit will take place. You should move the commit statement outside the if block as:



 if (t.getId() == null) {
em.persist(t);
}
em.getTransaction().commit();





share|improve this answer
























  • The commit() row still been skipped

    – Leandro Souza
    Nov 22 '18 at 4:38











  • Can you explain what exactly you mean by " commit() row still been skipped "

    – codeLover
    Nov 22 '18 at 4:41











  • When I get to persist() row and click to move to the next row it goes directly to em.close() on debug mode. It's like em.getTransaction().commit(); doesn't exist.

    – Leandro Souza
    Nov 22 '18 at 4:52











  • you mean a Throwable is thrown. So DEBUG YOUR CODE and look at what Throwable is thrown!

    – Billy Frost
    Nov 22 '18 at 10:02
















0














On a higher level, it seems the issue is because of the place you have kept your commit statement. You have kept it inside the if condition, so the commit happens only when the if condition is satisfied. For instance, in the sample input data shared by you id is not null, therefore, if condition is not satisfied, thus, commit won't take place, on the contrary if you will send entity with null id, commit will take place. You should move the commit statement outside the if block as:



 if (t.getId() == null) {
em.persist(t);
}
em.getTransaction().commit();





share|improve this answer
























  • The commit() row still been skipped

    – Leandro Souza
    Nov 22 '18 at 4:38











  • Can you explain what exactly you mean by " commit() row still been skipped "

    – codeLover
    Nov 22 '18 at 4:41











  • When I get to persist() row and click to move to the next row it goes directly to em.close() on debug mode. It's like em.getTransaction().commit(); doesn't exist.

    – Leandro Souza
    Nov 22 '18 at 4:52











  • you mean a Throwable is thrown. So DEBUG YOUR CODE and look at what Throwable is thrown!

    – Billy Frost
    Nov 22 '18 at 10:02














0












0








0







On a higher level, it seems the issue is because of the place you have kept your commit statement. You have kept it inside the if condition, so the commit happens only when the if condition is satisfied. For instance, in the sample input data shared by you id is not null, therefore, if condition is not satisfied, thus, commit won't take place, on the contrary if you will send entity with null id, commit will take place. You should move the commit statement outside the if block as:



 if (t.getId() == null) {
em.persist(t);
}
em.getTransaction().commit();





share|improve this answer













On a higher level, it seems the issue is because of the place you have kept your commit statement. You have kept it inside the if condition, so the commit happens only when the if condition is satisfied. For instance, in the sample input data shared by you id is not null, therefore, if condition is not satisfied, thus, commit won't take place, on the contrary if you will send entity with null id, commit will take place. You should move the commit statement outside the if block as:



 if (t.getId() == null) {
em.persist(t);
}
em.getTransaction().commit();






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 4:32









codeLovercodeLover

2,2591520




2,2591520













  • The commit() row still been skipped

    – Leandro Souza
    Nov 22 '18 at 4:38











  • Can you explain what exactly you mean by " commit() row still been skipped "

    – codeLover
    Nov 22 '18 at 4:41











  • When I get to persist() row and click to move to the next row it goes directly to em.close() on debug mode. It's like em.getTransaction().commit(); doesn't exist.

    – Leandro Souza
    Nov 22 '18 at 4:52











  • you mean a Throwable is thrown. So DEBUG YOUR CODE and look at what Throwable is thrown!

    – Billy Frost
    Nov 22 '18 at 10:02



















  • The commit() row still been skipped

    – Leandro Souza
    Nov 22 '18 at 4:38











  • Can you explain what exactly you mean by " commit() row still been skipped "

    – codeLover
    Nov 22 '18 at 4:41











  • When I get to persist() row and click to move to the next row it goes directly to em.close() on debug mode. It's like em.getTransaction().commit(); doesn't exist.

    – Leandro Souza
    Nov 22 '18 at 4:52











  • you mean a Throwable is thrown. So DEBUG YOUR CODE and look at what Throwable is thrown!

    – Billy Frost
    Nov 22 '18 at 10:02

















The commit() row still been skipped

– Leandro Souza
Nov 22 '18 at 4:38





The commit() row still been skipped

– Leandro Souza
Nov 22 '18 at 4:38













Can you explain what exactly you mean by " commit() row still been skipped "

– codeLover
Nov 22 '18 at 4:41





Can you explain what exactly you mean by " commit() row still been skipped "

– codeLover
Nov 22 '18 at 4:41













When I get to persist() row and click to move to the next row it goes directly to em.close() on debug mode. It's like em.getTransaction().commit(); doesn't exist.

– Leandro Souza
Nov 22 '18 at 4:52





When I get to persist() row and click to move to the next row it goes directly to em.close() on debug mode. It's like em.getTransaction().commit(); doesn't exist.

– Leandro Souza
Nov 22 '18 at 4:52













you mean a Throwable is thrown. So DEBUG YOUR CODE and look at what Throwable is thrown!

– Billy Frost
Nov 22 '18 at 10:02





you mean a Throwable is thrown. So DEBUG YOUR CODE and look at what Throwable is thrown!

– Billy Frost
Nov 22 '18 at 10:02


















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%2f53423750%2fjpa-commit-row-skiped-after-persist%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

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'