How can I create a function when using JPA ?

23 views
Skip to first unread message

BakaOnigiri

unread,
Feb 19, 2017, 5:42:40 PM2/19/17
to Xerial
Hello, I am trying to insert data in a database where a custom function is call in a trigger after the insertion.

But as I am using JPA, I tryied this code :

   
    public EntityManager newEm()
   
{
       
final EntityManager em = emf.createEntityManager();

       
final Connection connection = em.unwrap(Connection.class);
       
try
       
{
           
Function.create(connection, "title_sort", new Function()
           
{
               
@Override
               
protected void xFunc() throws SQLException
               
{
                    result
(value_text(0));
               
}
           
});
       
}
       
catch(final SQLException e)
       
{
            LOGGER
.error("!!!!!", e);
       
}

       
return em;
   
}

As you can see, I am trying to add the function on the entity manager, but the Connection instance is not recognized, and therefore the insertion fail.


Any idea on how to do so ?

Thanks.

Best regards.



Reply all
Reply to author
Forward
0 new messages