精华内容
下载资源
问答
  • SAP如何删除数据表中的数据

    千次阅读 2019-06-28 11:44:44
    "DELETE FROM [表名]",删除表中的全部数据。 DELETE FROM ZMATNR_HISTORY. 方法二 通过SE14删除全部数据。方法三 se16进入,运行,选中要删除的数据,双击选中的第一条数据,在menu中输入‘/h’,回车,显示...

    方法一
    通过DELETE FROM语句删除。"DELETE FROM [表名]",删除表中的全部数据。

    DELETE FROM ZMATNR_HISTORY.

    方法二
    通过SE14删除全部数据。


    方法三
    se16进入,运行,选中要删除的数据,双击选中的第一条数据,在menu中输入‘/h’,回车,显示‘调试被激活’。


    再回车,进入调试环境,双击code,将‘SHOW’改为‘DELE’,按F8,屏幕中出现,点击删除条目,显示‘数据库记录已删除’。此时仅删除当前数据,继续点击‘删除条目’,即可将下面的数据删除,一条一条删。刷新数据库,即可看见,选中的数据被删除了。



    方法四
    输入要删除数据的自定义表名,回车。进入后,在menu中输tcode:&sap_edit,回车,点击运行,即可进入修改界面。

    展开全文
  • SAP删除数据表中的数据

    千次阅读 2011-06-13 17:31:00
    故可采用此方法来编写程序删除数据表中的记录。 此方法不够直接,存在风险,对有些不易取到的数据,可能不太有效。   方法二:使用事务码-SE16N; 输入自己要修改的表名,回车,然后输入事务码-&sap_edit来...

    SAP中删除数据库表中数据的方法有很多,今天给它来个小结。

     

    方法一:ABAP语言中OPEN SQL 有从数据库中删除记录的语句。故可采用此方法来编写程序删除数据表中的记录。

    此方法不够直接,存在风险,对有些不易取到的数据,可能不太有效。

     

    方法二:使用事务码-SE16N;

    输入自己要修改的表名,回车,然后输入事务码-&sap_edit来激活编辑状态。回车,点击运行,即可进行修改。

    此方法好像不能修改主键,所以使用范围比较小。

     

    方法三:使用事务码-SE16;

    使用事务码SE38打开程序LSETBF01,查找字符‘SHOW’设置断点。

    使用事务码SE16打开要修改的数据表。查出要删除的数据,并选中它。点击查看按钮或者双击,进入调试环境,程序停在CODE处,双击CODE 修改其值为'DELE',然后点击运行进入下一屏幕,点击删除数据即可。删除以后点下一条,可以删除其它选中的记录。

    此方法,比较冒险,少用。

    展开全文
  • 在把表的自增长设置为1) DELETE FROM grade; ALTER TABLE grade AUTO_INCREMENT=1; 方式2 使用truncate清空全部数据主键自增长是从1开始(效率更高) truncate table "名字"...

    1 方式一

    清空表数据并且将主键自增长从1开始(1.先清空表数据2.在把表的自增长设置为1)

    
    DELETE FROM grade;  
    
    ALTER TABLE grade AUTO_INCREMENT=1;  

    方式2

    使用truncate清空全部数据主键自增长是从1开始(效率更高)

    truncate table "表名字"
    展开全文
  • 当时的测试是忘H2数据库插入多项数据,然后用Query的方式删除,assert读出来的数据是null。这个测试用例在EclipseLink下面是可以通过的,但换成Hibernate之后发现数据仍然可以读出这个数据。 测试用例如下: @Tes

    前段时间把项目中的JPA从EclipseLink换成Hibernate。这其中遇到了很多问题,也记录了一部分在其他的文章中。这里介绍一个UT中遇到的问题。
    当时的测试是忘H2数据库中插入多项数据,然后用Query的方式删除,assert读出来的数据是null。这个测试用例在EclipseLink下面是可以通过的,但换成Hibernate之后发现数据仍然可以读出这个数据。
    测试用例如下:

     @Test
        public void shouldRemovesAllFmReportFromDb()
        {
            FmReport fmReport1 = givenFmReportIsStoredInDb();
            FmReport fmReport2 = givenFmReportIsStoredInDb();
            FmReport fmReport3 = givenFmReportIsStoredInDb();
    
            Integer previousSize = getEntityManager().createQuery( "SELECT re FROM FmReport re" ).getResultList().size();
            System.out.println("*** before delete, the size is " + previousSize);
    
            FmReport fmReportById1 = getEntityManager().find(FmReport.class, fmReport1.getId());
            Assert.assertNotNull( fmReportById1 );
    
    
            getEntityManager().createQuery( "DELETE FROM FmReport" ).executeUpdate();
    
            Integer finalSize = getEntityManager().createQuery( "SELECT re FROM FmReport re" ).getResultList().size();
            System.out.println("*** after delete, the size is " + finalSize);
    
            Assert.assertNull( getEntityManager().find(FmReport.class, fmReport1.getId()));
        }

    测试的log:

    18:25:36.027 [main] DEBUG o.h.hql.internal.ast.ErrorCounter - throwQueryException() : no errors
    18:25:36.029 [main] DEBUG o.h.hql.internal.ast.ErrorCounter - throwQueryException() : no errors
    18:25:36.029 [main] DEBUG o.h.internal.SessionFactoryImpl - Checking 0 named SQL queries
    18:25:36.042 [main] DEBUG o.h.s.internal.StatisticsInitiator - Statistics initialized [enabled=false]
    18:25:36.105 [main] DEBUG o.h.e.i.EntityManagerFactoryRegistry - Initializing EntityManagerFactoryRegistry : org.hibernate.ejb.internal.EntityManagerFactoryRegistry@6ef93d8a
    18:25:36.105 [main] DEBUG o.h.e.i.EntityManagerFactoryRegistry - Registering EntityManagerFactory: test-pu 18:25:36.216 [main] DEBUG o.h.e.t.spi.AbstractTransactionImpl - begin
    18:25:36.216 [main] DEBUG o.h.e.j.i.LogicalConnectionImpl - Obtaining JDBC connection
    18:25:36.216 [main] DEBUG o.h.e.j.i.LogicalConnectionImpl - Obtained JDBC connection
    18:25:36.216 [main] DEBUG o.h.e.t.i.jdbc.JdbcTransaction - initial autocommit status: true
    18:25:36.216 [main] DEBUG o.h.e.t.i.jdbc.JdbcTransaction - disabling autocommit
    18:25:36.223 [main] DEBUG org.hibernate.SQL - select nextval ('fm_report_id_seq')
    18:25:36.231 [main] DEBUG org.hibernate.id.SequenceGenerator - Sequence identifier generated: BasicHolder[java.lang.Long[1]]
    18:25:36.234 [main] DEBUG o.h.e.i.AbstractSaveEventListener - Generated identifier: 1, using strategy: org.hibernate.id.SequenceHiLoGenerator
    18:25:36.249 [main] DEBUG org.hibernate.SQL - select nextval ('fm_report_id_seq')
    18:25:36.249 [main] DEBUG org.hibernate.id.SequenceGenerator - Sequence identifier generated: BasicHolder[java.lang.Long[2]]
    18:25:36.249 [main] DEBUG o.h.e.i.AbstractSaveEventListener - Generated identifier: 2, using strategy: org.hibernate.id.SequenceHiLoGenerator
    18:25:36.250 [main] DEBUG org.hibernate.SQL - select nextval ('fm_report_id_seq')
    18:25:36.250 [main] DEBUG org.hibernate.id.SequenceGenerator - Sequence identifier generated: BasicHolder[java.lang.Long[3]]
    18:25:36.250 [main] DEBUG o.h.e.i.AbstractSaveEventListener - Generated identifier: 3, using strategy: org.hibernate.id.SequenceHiLoGenerator
    18:25:36.268 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Processing flush-time cascades
    18:25:36.270 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Dirty checking collections
    18:25:36.273 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Flushed: 3 insertions, 0 updates, 0 deletions to 3 objects
    18:25:36.273 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
    18:25:36.274 [main] DEBUG o.h.internal.util.EntityPrinter - Listing entities:
    18:25:36.277 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=3, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.277 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=2, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.277 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=1, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.277 [main] DEBUG org.hibernate.engine.spi.ActionQueue - Changes must be flushed to space: fm_report
    18:25:36.289 [main] DEBUG org.hibernate.SQL - insert into fm_report (alarms_json, date, id) values (?, ?, ?)
    18:25:36.295 [main] DEBUG org.hibernate.SQL - insert into fm_report (alarms_json, date, id) values (?, ?, ?)
    18:25:36.296 [main] DEBUG org.hibernate.SQL - insert into fm_report (alarms_json, date, id) values (?, ?, ?)
    18:25:36.300 [main] DEBUG org.hibernate.SQL - select fmreport0_.id as id1_0_, fmreport0_.alarms_json as alarms_j2_0_, fmreport0_.date as date3_0_ from fm_report fmreport0_
    18:25:36.302 [main] DEBUG org.hibernate.loader.Loader - Result set row: 0
    18:25:36.306 [main] DEBUG org.hibernate.loader.Loader - Result row: EntityKey[FmReport#1]
    18:25:36.307 [main] DEBUG org.hibernate.loader.Loader - Result set row: 1
    18:25:36.308 [main] DEBUG org.hibernate.loader.Loader - Result row: EntityKey[FmReport#2]
    18:25:36.309 [main] DEBUG org.hibernate.loader.Loader - Result set row: 2
    18:25:36.309 [main] DEBUG org.hibernate.loader.Loader - Result row: EntityKey[FmReport#3]
    *** before delete, the size is 3
    18:25:36.322 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Processing flush-time cascades
    18:25:36.323 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Dirty checking collections
    18:25:36.323 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Flushed: 0 insertions, 0 updates, 0 deletions to 3 objects
    18:25:36.324 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
    18:25:36.324 [main] DEBUG o.h.internal.util.EntityPrinter - Listing entities:
    18:25:36.324 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=3, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.324 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=2, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.324 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=1, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.330 [main] DEBUG org.hibernate.SQL - delete from fm_report
    18:25:36.334 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Processing flush-time cascades
    18:25:36.335 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Dirty checking collections
    18:25:36.337 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Flushed: 0 insertions, 0 updates, 0 deletions to 3 objects
    18:25:36.337 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
    18:25:36.337 [main] DEBUG o.h.internal.util.EntityPrinter - Listing entities:
    18:25:36.337 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=3, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.338 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=2, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.338 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=1, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.338 [main] DEBUG org.hibernate.SQL - select fmreport0_.id as id1_0_, fmreport0_.alarms_json as alarms_j2_0_, fmreport0_.date as date3_0_ from fm_report fmreport0_
    *** after delete, the size is 0
    18:25:36.338 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Processing flush-time cascades
    18:25:36.339 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Dirty checking collections
    18:25:36.339 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Flushed: 0 insertions, 0 updates, 0 deletions to 3 objects
    18:25:36.339 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
    18:25:36.339 [main] DEBUG o.h.internal.util.EntityPrinter - Listing entities:
    18:25:36.339 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=3, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.339 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=2, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.339 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=1, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.339 [main] DEBUG o.h.e.t.spi.AbstractTransactionImpl - rolling back
    18:25:36.343 [main] DEBUG o.h.e.t.i.jdbc.JdbcTransaction - rolled JDBC Connection
    18:25:36.343 [main] DEBUG o.h.e.t.i.jdbc.JdbcTransaction - re-enabling autocommit
    18:25:36.346 [main] DEBUG o.h.e.j.internal.JdbcCoordinatorImpl - HHH000420: Closing un-released batch
    18:25:36.346 [main] DEBUG o.h.e.j.i.LogicalConnectionImpl - Releasing JDBC connection
    18:25:36.346 [main] DEBUG o.h.e.j.i.LogicalConnectionImpl - Released JDBC connection
    
    java.lang.AssertionError: expected null, but was:<FmReport@88dfd83>

    可以在Log中明显看到执行了对应的删除的sql语句:
    18:25:36.330 [main] DEBUG org.hibernate.SQL - delete from fm_report
    并且再用select语句读取数据库时,数据是真实从数据库中删掉了的,但为什么entityManager的find()函数还是能够读取到对应的entity呢?
    并且entity printer的打印显示它们仍然存在:

    18:25:36.339 [main] DEBUG o.h.internal.util.EntityPrinter - Listing entities:
    18:25:36.339 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=3, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.339 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=2, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    18:25:36.339 [main] DEBUG o.h.internal.util.EntityPrinter - FmReport{id=1, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}

    分析得出的结论是:

    • hibernate query的executeUpdate()是直接对数据库进行操作
    • executeUpdate()不对cache进行更新,executeUpdate()会造成find()和query select的不同步。

    这点在JBoss的官网上有描述:

    http://docs.jboss.org/hibernate/core/3.3/reference/en/html/batch.html#batch-direct

    This means that manipulating data directly in the database (using the SQL Data Manipulation Language (DML) the statements: INSERT, UPDATE, DELETE) will not affect in-memory state. However, Hibernate provides methods for bulk SQL-style DML statement execution that is performed through the Hibernate Query Language (HQL).

    并且,hibernate做了多次的dirty checking collections:

        Line 21: 18:25:36.270 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Dirty checking collections
        Line 41: 18:25:36.323 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Dirty checking collections
        Line 50: 18:25:36.335 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Dirty checking collections
        Line 60: 18:25:36.339 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Dirty checking collections

    可见,除了出现在hibernate中使用query是有比较大的performance的开销。
    但注意,这个问题不是common的,不同的JPA有不同的实现方式,EclipseLink就没有这个问题。
    那我们该怎么解决呢?
    问题的关键在于同步cache/mem中的数据与数据库同步,调用clear()函数可以解决这个问题:

            getEntityManager().clear();
            getEntityManager().createQuery( "delete FmReport" ).executeUpdate();

    Log:

    14:14:16.348 [main] DEBUG o.h.h.i.ast.QueryTranslatorImpl - --- HQL AST ---
     \-[DELETE] Node: 'DELETE'
        \-[FROM] Node: 'FROM'
           \-[RANGE] Node: 'RANGE'
              \-[DOT] Node: '.'
                 +-[DOT] Node: '.'
                 |  +-[DOT] Node: '.'
                 |  |  +-[DOT] Node: '.'
                 |  |  |  +-[DOT] Node: '.'
                 |  |  |  |  +-[DOT] Node: '.'
                 |  |  |  |  |  +-[DOT] Node: '.'
                 |  |  |  |  |  |  +-[DOT] Node: '.'
                 |  |  |  |  |  |  |  +-[DOT] Node: '.'
                 |  |  |  |  |  |  |  |  +-[DOT] Node: '.'
                 |  |  |  |  |  |  |  |  |  +-[IDENT] Node: 'com'
                 |  |  |  |  |  |  |  |  |  \-[IDENT] Node: 'nsn'
                 |  |  |  |  |  |  |  |  \-[IDENT] Node: 'ood'
                 |  |  |  |  |  |  |  \-[IDENT] Node: 'cp'
                 |  |  |  |  |  |  \-[IDENT] Node: 'aswu'
                 |  |  |  |  |  \-[IDENT] Node: 'fm'
                 |  |  |  |  \-[IDENT] Node: 'nms'
                 |  |  |  \-[IDENT] Node: 'db'
                 |  |  \-[IDENT] Node: 'report'
                 |  \-[IDENT] Node: 'domain'
                 \-[IDENT] Node: 'FmReport'
    
    14:14:16.348 [main] DEBUG o.h.hql.internal.ast.ErrorCounter - throwQueryException() : no errors
    14:14:16.352 [main] DEBUG o.h.h.i.antlr.HqlSqlBaseWalker - delete << begin [level=1, statement=delete]
    14:14:16.353 [main] DEBUG o.h.h.internal.ast.tree.FromElement - FromClause{level=1} : com.nsn.ood.cp.aswu.fm.nms.db.report.domain.FmReport (<no alias>) -> fmreport0_
    14:14:16.354 [main] DEBUG o.h.h.i.antlr.HqlSqlBaseWalker - delete : finishing up [level=1, statement=delete]
    14:14:16.354 [main] DEBUG o.h.h.i.antlr.HqlSqlBaseWalker - delete >> end [level=1, statement=delete]
    14:14:16.355 [main] DEBUG o.h.h.i.ast.QueryTranslatorImpl - --- SQL AST ---
     \-[DELETE] DeleteStatement: 'DELETE'  querySpaces (fm_report)
        \-[FROM] FromClause: 'FROM' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[], fromElementByTableAlias=[fmreport0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
           \-[FROM_FRAGMENT] FromElement: 'fm_report' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=fm_report,tableAlias=fmreport0_,origin=null,columns={,className=com.nsn.ood.cp.aswu.fm.nms.db.report.domain.FmReport}}
    
    14:14:16.355 [main] DEBUG o.h.hql.internal.ast.ErrorCounter - throwQueryException() : no errors
    14:14:16.358 [main] DEBUG o.h.hql.internal.ast.ErrorCounter - throwQueryException() : no errors
    14:14:16.358 [main] DEBUG o.h.internal.SessionFactoryImpl - Checking 0 named SQL queries
    14:14:16.369 [main] DEBUG o.h.s.internal.StatisticsInitiator - Statistics initialized [enabled=false]
    14:14:16.449 [main] DEBUG o.h.e.i.EntityManagerFactoryRegistry - Initializing EntityManagerFactoryRegistry : org.hibernate.ejb.internal.EntityManagerFactoryRegistry@775dfcbc
    14:14:16.449 [main] DEBUG o.h.e.i.EntityManagerFactoryRegistry - Registering EntityManagerFactory: test-pu 14:14:16.589 [main] DEBUG o.h.e.t.spi.AbstractTransactionImpl - begin
    14:14:16.589 [main] DEBUG o.h.e.j.i.LogicalConnectionImpl - Obtaining JDBC connection
    14:14:16.589 [main] DEBUG o.h.e.j.i.LogicalConnectionImpl - Obtained JDBC connection
    14:14:16.589 [main] DEBUG o.h.e.t.i.jdbc.JdbcTransaction - initial autocommit status: true
    14:14:16.589 [main] DEBUG o.h.e.t.i.jdbc.JdbcTransaction - disabling autocommit
    14:14:16.597 [main] DEBUG org.hibernate.SQL - select nextval ('fm_report_id_seq')
    14:14:16.619 [main] DEBUG org.hibernate.id.SequenceGenerator - Sequence identifier generated: BasicHolder[java.lang.Long[1]]
    14:14:16.624 [main] DEBUG o.h.e.i.AbstractSaveEventListener - Generated identifier: 1, using strategy: org.hibernate.id.SequenceHiLoGenerator
    14:14:16.644 [main] DEBUG org.hibernate.SQL - select nextval ('fm_report_id_seq')
    14:14:16.645 [main] DEBUG org.hibernate.id.SequenceGenerator - Sequence identifier generated: BasicHolder[java.lang.Long[2]]
    14:14:16.645 [main] DEBUG o.h.e.i.AbstractSaveEventListener - Generated identifier: 2, using strategy: org.hibernate.id.SequenceHiLoGenerator
    14:14:16.645 [main] DEBUG org.hibernate.SQL - select nextval ('fm_report_id_seq')
    14:14:16.645 [main] DEBUG org.hibernate.id.SequenceGenerator - Sequence identifier generated: BasicHolder[java.lang.Long[3]]
    14:14:16.645 [main] DEBUG o.h.e.i.AbstractSaveEventListener - Generated identifier: 3, using strategy: org.hibernate.id.SequenceHiLoGenerator
    14:14:16.665 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Processing flush-time cascades
    14:14:16.666 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Dirty checking collections
    14:14:16.669 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Flushed: 3 insertions, 0 updates, 0 deletions to 3 objects
    14:14:16.669 [main] DEBUG o.h.e.i.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
    14:14:16.672 [main] DEBUG o.h.internal.util.EntityPrinter - Listing entities:
    14:14:16.675 [main] DEBUG o.h.internal.util.EntityPrinter - com.nsn.ood.cp.aswu.fm.nms.db.report.domain.FmReport{id=3, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    14:14:16.675 [main] DEBUG o.h.internal.util.EntityPrinter - com.nsn.ood.cp.aswu.fm.nms.db.report.domain.FmReport{id=2, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    14:14:16.676 [main] DEBUG o.h.internal.util.EntityPrinter - com.nsn.ood.cp.aswu.fm.nms.db.report.domain.FmReport{id=1, alarmsJson=jsonString, date=Thu Jan 01 08:00:00 CST 1970}
    14:14:16.676 [main] DEBUG org.hibernate.engine.spi.ActionQueue - Changes must be flushed to space: fm_report
    14:14:16.693 [main] DEBUG org.hibernate.SQL - insert into fm_report (alarms_json, date, id) values (?, ?, ?)
    14:14:16.702 [main] DEBUG org.hibernate.SQL - insert into fm_report (alarms_json, date, id) values (?, ?, ?)
    14:14:16.703 [main] DEBUG org.hibernate.SQL - insert into fm_report (alarms_json, date, id) values (?, ?, ?)
    14:14:16.711 [main] DEBUG org.hibernate.SQL - select fmreport0_.id as id1_0_, fmreport0_.alarms_json as alarms_j2_0_, fmreport0_.date as date3_0_ from fm_report fmreport0_
    14:14:16.712 [main] DEBUG org.hibernate.loader.Loader - Result set row: 0
    14:14:16.715 [main] DEBUG org.hibernate.loader.Loader - Result row: EntityKey[com.nsn.ood.cp.aswu.fm.nms.db.report.domain.FmReport#1]
    14:14:16.715 [main] DEBUG org.hibernate.loader.Loader - Result set row: 1
    14:14:16.715 [main] DEBUG org.hibernate.loader.Loader - Result row: EntityKey[com.nsn.ood.cp.aswu.fm.nms.db.report.domain.FmReport#2]
    14:14:16.715 [main] DEBUG org.hibernate.loader.Loader - Result set row: 2
    14:14:16.715 [main] DEBUG org.hibernate.loader.Loader - Result row: EntityKey[com.nsn.ood.cp.aswu.fm.nms.db.report.domain.FmReport#3]
    *** before delete, the size is 3
    14:14:16.723 [main] DEBUG o.h.h.i.ast.QueryTranslatorImpl - parse() - HQL: delete com.nsn.ood.cp.aswu.fm.nms.db.report.domain.FmReport
    14:14:16.726 [main] DEBUG o.h.h.i.ast.QueryTranslatorImpl - --- HQL AST ---
     \-[DELETE] Node: 'delete'
        \-[FROM] Node: 'FROM'
           \-[RANGE] Node: 'RANGE'
              \-[DOT] Node: '.'
                 +-[DOT] Node: '.'
                 |  +-[DOT] Node: '.'
                 |  |  +-[DOT] Node: '.'
                 |  |  |  +-[DOT] Node: '.'
                 |  |  |  |  +-[DOT] Node: '.'
                 |  |  |  |  |  +-[DOT] Node: '.'
                 |  |  |  |  |  |  +-[DOT] Node: '.'
                 |  |  |  |  |  |  |  +-[DOT] Node: '.'
                 |  |  |  |  |  |  |  |  +-[DOT] Node: '.'
                 |  |  |  |  |  |  |  |  |  +-[IDENT] Node: 'com'
                 |  |  |  |  |  |  |  |  |  \-[IDENT] Node: 'nsn'
                 |  |  |  |  |  |  |  |  \-[IDENT] Node: 'ood'
                 |  |  |  |  |  |  |  \-[IDENT] Node: 'cp'
                 |  |  |  |  |  |  \-[IDENT] Node: 'aswu'
                 |  |  |  |  |  \-[IDENT] Node: 'fm'
                 |  |  |  |  \-[IDENT] Node: 'nms'
                 |  |  |  \-[IDENT] Node: 'db'
                 |  |  \-[IDENT] Node: 'report'
                 |  \-[IDENT] Node: 'domain'
                 \-[IDENT] Node: 'FmReport'
    
    14:14:16.726 [main] DEBUG o.h.hql.internal.ast.ErrorCounter - throwQueryException() : no errors
    14:14:16.727 [main] DEBUG o.h.h.i.antlr.HqlSqlBaseWalker - delete << begin [level=1, statement=delete]
    14:14:16.727 [main] DEBUG o.h.h.internal.ast.tree.FromElement - FromClause{level=1} : com.nsn.ood.cp.aswu.fm.nms.db.report.domain.FmReport (<no alias>) -> fmreport0_
    14:14:16.727 [main] DEBUG o.h.h.i.antlr.HqlSqlBaseWalker - delete : finishing up [level=1, statement=delete]
    14:14:16.727 [main] DEBUG o.h.h.i.antlr.HqlSqlBaseWalker - delete >> end [level=1, statement=delete]
    14:14:16.728 [main] DEBUG o.h.h.i.ast.QueryTranslatorImpl - --- SQL AST ---
     \-[DELETE] DeleteStatement: 'delete'  querySpaces (fm_report)
        \-[FROM] FromClause: 'FROM' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[], fromElementByTableAlias=[fmreport0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
           \-[FROM_FRAGMENT] FromElement: 'fm_report' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=fm_report,tableAlias=fmreport0_,origin=null,columns={,className=com.nsn.ood.cp.aswu.fm.nms.db.report.domain.FmReport}}
    
    14:14:16.728 [main] DEBUG o.h.hql.internal.ast.ErrorCounter - throwQueryException() : no errors
    14:14:16.728 [main] DEBUG o.h.hql.internal.ast.ErrorCounter - throwQueryException() : no errors
    14:14:16.730 [main] DEBUG org.hibernate.SQL - delete from fm_report
    14:14:16.732 [main] DEBUG org.hibernate.SQL - select fmreport0_.id as id1_0_, fmreport0_.alarms_json as alarms_j2_0_, fmreport0_.date as date3_0_ from fm_report fmreport0_
    *** after delete, the size is 0
    14:14:16.733 [main] DEBUG org.hibernate.loader.Loader - Loading entity: [com.nsn.ood.cp.aswu.fm.nms.db.report.domain.FmReport#1]
    14:14:16.733 [main] DEBUG org.hibernate.SQL - select fmreport0_.id as id1_0_0_, fmreport0_.alarms_json as alarms_j2_0_0_, fmreport0_.date as date3_0_0_ from fm_report fmreport0_ where fmreport0_.id=?
    14:14:16.733 [main] DEBUG org.hibernate.loader.Loader - Done entity load
    14:14:16.734 [main] DEBUG o.h.e.t.spi.AbstractTransactionImpl - rolling back
    14:14:16.738 [main] DEBUG o.h.e.t.i.jdbc.JdbcTransaction - rolled JDBC Connection
    14:14:16.738 [main] DEBUG o.h.e.t.i.jdbc.JdbcTransaction - re-enabling autocommit
    14:14:16.739 [main] DEBUG o.h.e.j.internal.JdbcCoordinatorImpl - HHH000420: Closing un-released batch
    14:14:16.739 [main] DEBUG o.h.e.j.i.LogicalConnectionImpl - Releasing JDBC connection
    14:14:16.739 [main] DEBUG o.h.e.j.i.LogicalConnectionImpl - Released JDBC connection

    这下清爽了许多,而且也没有了dirty checking的开销

    但需要注意的是:

        /**
         * Clear the persistence context, causing all managed
         * entities to become detached. Changes made to entities that
         * have not been flushed to the database will not be
         * persisted.
         */
        public void clear();

    如果在clear之前我们有还有没提交的transaction, 那之前保存在内存中还没提交到数据库的修改就会被丢弃。
    因此,所有的saveOrUpdate操作必须有事务控制。
    另外,关于何时调用clear()函数是有比较好的总结的:

    Clearing the entity manager empties its associated cache, forcing new database queries to be executed later in the transaction. It’s almost never necessary to clear the entity manager when using a transaction-bound entity manager. I see two reasons to clear:

    • when doing batch processing, in order to avoid having a giant cache eating memory and increasing the time to flush because of long dirty checks
    • when you’re doing DML or SQL queries, which completely bypass the entity manager cache. In this case, the state held by the cache doesn’t reflect what is in the database because of the queries, so you want to clear the cache to avoid this inconsistency.
    展开全文
  • 1、清空不带外键约束的数据表中的数据 使用delete语句清空`t_test`表中的数据 delete from `t_test`; 使用truncate语句清空`t_test`表中的数据 truncate table `t_test`; delete语句清空和truncate语句...
  • 目录 零、码仙励志 一、数据表中数据增加(插入) 二、数据表中数据查询 三、数据表中数据修改 ...这篇文章写是:SQL Server数据表中数据增加(插入)、查询、修改、删除 不是:SQL Server中...
  • truncate——删除hive表中的数据

    万次阅读 2018-07-25 13:21:34
    在某些情况下,我们需要在不删除表的情况下,删除表中的数据。像Oracle、MySQL数据库,可以使用如下语言删除表中的数据: DELETE FROM tableName;  在Hive中,上面的语句就不那么好用了,我们可以使用truncate来...
  • 一、如何删除较大的表 两个删除策略: 1、慢的方法是写脚本定时任务带where的delete语句 ...情景:数据库中有一张表t_aa , 表中数据包含了2年的数据,将近3000万条记录,目前需要清除一年的历史数据。 有人说很简...
  • 希望你也加入到人工智能队伍来!请点击http://www.captainbed.net /* * Created by Chimomo * * Sort both lists in ascending order. And then use the following code. */ #include &lt;iostr...
  • Hive删除表中数据

    万次阅读 2019-07-12 11:40:44
    (truncate用于删除所有行,这个行为在hive元存储删除数据是不可逆) 或delete from 表名 where 1 = 1 ; (delete用于删除特定条件下行,使用where 1=1 删除所有行SQLwhere 1 = 1 使用) truncate 不能...
  • mysql中删除数据表数据两种方式

    千次阅读 2017-12-11 15:26:27
    一、今天在写存储过程时,需要制执行前清空数据表,于是乎用了delete from table 方式,后来被告知这种写法针对数据多时候其效率会降低,于是乎就有了下面东西, 二、delete from tableName 和 truncate table...
  • SQL Server中如何删除表,如何删除表中的数据删除表的T-SQL语句为:drop table &lt;表名&gt;drop是丢弃的意思,drop table表示将一个表彻底删除掉。删除表数据有两种方法:delete和truncate。delete的用法...
  • 用sql语句删除数据表中重复的数据

    千次阅读 2009-05-22 13:35:00
    在实习中,用“小偷”程序采集到了大量的数据,可是有不少的是重复的,根据实习要求把重复的数据删除(要保留一条记录),另外还要把几个数据表中的数据合并,放在一个数据表中。根据自己尝试的经验,把几点下来。1...
  • 删除表数据时有 delete 和 truncate 两种方法 删除表的 T-SQL 语句为: drop table mytablename 删除表数据有两种方法:delete 和 truncate。 delete from mytablename [where条件] truncate table ...
  • 在insert所在的类中加一个删除的方法即可, 方法中的代码很简单,一行解决问题 database.execSQL("drop table if exists " + TABLE_NAME); //这个是将表删除 ... //删除表中的数据,表还是要保留的
  • MYSQL 删除表中的重复数据

    万次阅读 2018-08-23 15:30:43
    test表中的原始数据:   test表中name字段信息有重复,想进行过滤删除重复数据 删除重复数据之后的预期结果(不考虑id)...先创建临时表tab,新表tab中的数据时从test表中分组查询出来的 create table tab select...
  • 想实现的功能:删除BOOK表中的一行数据时删除与PAGEVIEW表中BOOKID相等的数据行 实现方法:在BOOK表中建立一个触发器BOOK_TRG_DELETE,具体实现语句如下: create or replace trigger BOOK_TRG_DELETE  bdfore ...
  • 数据库删除表中数据

    千次阅读 2019-03-27 11:37:48
    数据库删除表中数据,如果直接清空数据,id自增长的话,再添加的数据会从清除之前的id继续自增长,想要删除数据,id 自增长仍然从1开始,如下操作: show create TABLE Analysis.ORDER_SUMM 执行以上语句结果如下:...
  • SQL Server中,删除表,删除表中数据

    万次阅读 2016-12-22 12:12:23
    SQL Server,我们现在基本上使用的最古老的版本应该是SQL...今天我们就来说说如何使用T-SQL脚本来删除表,以及删除表中的数据删除表和删除表数据这是两回事!删除表表示不管表中有没有数据,将该数据库表彻底抹去

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 46,678
精华内容 18,671
关键字:

删除数据表中的数据