Hi , did you solve the problem?

Mine is a little different, due to different configuration of Spring MVC, 
Hibernate H2 (config was made by my predecessor, which left the company 
:-():

@Repository
public class TableLockRepositoryJPA  implements TableLockRepository{

    @PersistenceContext(unitName="persistenceUnit")
    EntityManager entityManager;
...
        public int BackUpDB(String filename)
        {
            int q = 0;
            // Save file
            try {
                filename = filename +"2";
                q =  entityManager.createNamedQuery("BACKUP TO 
':filename'", TableLock.class).executeUpdate();
                entityManager.getTransaction().commit();

            } catch (Exception e) {
                e.printStackTrace();
            }
            return q;
        }

When calling this:
entityManager  throws an Exception 


*InvalidDataAccessAPIUsageExceptionNormal queries like *TypedQuery<TableLock> 
q =  entityManager.createQuery("SELECT TableLock FROM TableLock AS 
tablelock WHERE tablelock.locked = :locked", TableLock.class);
            q.setParameter("locked", locked);

works perfectly.

Any guesses? I am also looking for an access to my database (of course when 
it is online), like you did it, but I do not know how to do it outside the 
persistence-units defined in persistence.xml:
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
...
            <class>com.bitsvalley.erestau.domain.TableLock</class>
...
          <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>

            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.ejb.naming_strategy" 
value="org.hibernate.cfg.ImprovedNamingStrategy"/>
            <property name="hibernate.connection.charSet" value="UTF-8"/>
            
            <!-- property name="hibernate.cache.use_second_level_cache" 
value="true"/ -->
            <!-- property name="hibernate.cache.use_query_cache" 
value="true"/ -->            
            <!-- property name="hibernate.cache.provider_class" 
value="org.hibernate.cache.EhCacheProvider"/ -->
            <!-- property name="hibernate.max_fetch_depth" value="0"/ -->
            
        </properties>
    </persistence-unit>

I would appreciate really any help of you!

Regards
Peter

Am Montag, 4. April 2016 06:59:37 UTC+2 schrieb abdou amer:
>
> I want to perform backup and restore using hibernate ORM, but i seems that 
> the below code not do any thing.
>
> So, what the propre way to perform backup and restore without corrupting the 
> database.
>
>
> File file = fileChooser.showSaveDialog(tbTabPaneHome.getScene().getWindow());
>         if (file != null) {
>             // Save file
>
>
>             try {
>
>
>                 Session session = 
> DatabaseUtil.getSessionFactory().openSession();
>                 session.beginTransaction();
>                 session.createSQLQuery("BACKUP TO '" + 
> file.getCanonicalPath() + "'");
>                 session.getTransaction().commit();
>                 session.close();
>
>
>             } catch (IOException e) {
>                 e.printStackTrace();
>             }
>
>         }
>
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to