JPA annotations = EJB3 annotations = Hibernate注释?(JPA annotations = EJB3 annotations = Hibernate annotations?)

我正在使用JBoss Tools将数据库模式反向工程为POJO。 具体来说,我在hibernatetool ANT任务中使用hbm2java选项。 在hbm2java选项下,您可以指定ejb3=true以在POJO中生成EJB3(JPA?)注释。 我的问题是这些注释是否是JPA注释? 或者,更一般地说,JPA注释,Hibernate注释和EJB3注释之间的区别是什么。 它们都基本相同吗?


I'm using JBoss Tools to reverse engineer a DB schema into POJO's. Specifically, I'm using the hbm2java option in the hibernatetool ANT task. Under the hbm2java option you can specify ejb3=true to have EJB3 (JPA?) annotations generated in your POJO's. My questions is whether these annotations are JPA annotations? Or, more generally, what is the difference between JPA annotations, Hibernate annotations and EJB3 annotations. Are they all essentially the same?


原文:https://stackoverflow.com/questions/7761186
2021-09-06 10:09

满意答案

你能做的最好的事情是创建自己的异常并抛出它。

class Exception : public std::exception
{
    public:                
        template< typename... Args >
        Exception( const std::string& msg, Args... args );

        virtual ~Exception() throw ();

        //! Overrides std::exception
        virtual const char* what() const throw();

    private:
        //! Log the message_
        void log() const;

    protected:
        std::string message_;
};

template< typename... Args >
Exception::Exception( const std::string& msg, Args... args )
    : message_( StrFmt::format( msg, args ... ) )
{
    log();
}

class MyException : public Exception
{
    MyException() : Exception( std::string("b must be different from 0") )
}

如果您计划在未捕获的异常上退出程序,则可以安装终止处理程序,在此处重新抛出异常。

static void terminate()
{
    static bool tried_rethrow = false;
    try
    {
        if ( !tried_rethrow )
        {
            tried_rethrow = true;
            throw;
        }
    }
    catch ( const std::runtime_error& err )
    {
        std::cout << err.what();
    }
    catch ( const Exception& err )
    {
        std::cout << err.what();
    }
    catch ( ... )
    {
    }
} 

在你的main.cpp中:

std::set_terminate( terminate );

这样就可以在一个地方处理所有未捕获的异常。


The best you can do is to create your own exception and throw that.

class Exception : public std::exception
{
    public:                
        template< typename... Args >
        Exception( const std::string& msg, Args... args );

        virtual ~Exception() throw ();

        //! Overrides std::exception
        virtual const char* what() const throw();

    private:
        //! Log the message_
        void log() const;

    protected:
        std::string message_;
};

template< typename... Args >
Exception::Exception( const std::string& msg, Args... args )
    : message_( StrFmt::format( msg, args ... ) )
{
    log();
}

class MyException : public Exception
{
    MyException() : Exception( std::string("b must be different from 0") )
}

If you further plan to exit the program on uncaught exceptions, it is possible to install a termination handler, where you rethrow the exception.

static void terminate()
{
    static bool tried_rethrow = false;
    try
    {
        if ( !tried_rethrow )
        {
            tried_rethrow = true;
            throw;
        }
    }
    catch ( const std::runtime_error& err )
    {
        std::cout << err.what();
    }
    catch ( const Exception& err )
    {
        std::cout << err.what();
    }
    catch ( ... )
    {
    }
} 

and in your main.cpp:

std::set_terminate( terminate );

That way it is possible to handle all uncaught exceptions at a single place.

相关问答

更多

Visual Studio 2013 - c ++代码映射错误消息(Visual Studio 2013 - c++ code map error message)

代码映射上的MSDN页面在要求下的C ++提供有限的支持。 Turns out it was my mistake and not a bug. I had incorrectly put includes in my headers such that almost all .cpp files included all .h files even if they weren't needed. It appears this caused the codemap application to ...

在C ++程序中的错误消息(Error message while in C++ program)

我怎么能避免以上终止? 通过重新思考你的设计。 你想达到什么目的? 特别是,为什么你需要一个内存中有2700万个条目的查找表? how can i avoid above termination? By rethinking your design. What are you trying to accomplish? In particular, why do you need a lookup table with 27 million entries in memory?

MySql“SET @variable”在C#代码中引发致命错误(MySql “SET @variable” throwing Fatal Error in C# code)

其实,我不认为你可以通过这行SET @oldguid = 250006; 到一个mysqlcommand对象(实际上我不知道)。 你应该做的是让你的程序把这些值放在一个局部变量中,然后替换更新查询中的参数。 找到一种方法来混合你的代码和这个: // This line should be outside the While loop Dictionary<string, string> variables = new Dictionary<string, strin...

错误消息C ++(Error Message C++)

你忘记了一个分号: template <typename T> class btree_iterator { }; ^ You forgot a semicolon: template <typename T> class btree_iterator { }; ^

芹菜抛出长的错误信息(Celery throwing long error message)

在github上有一个公开的问题,其中发现了相同的操作系统错误: https://github.com/celery/py-amqp/issues/130 有人在关于该问题的评论中建议, 通过将amqp版本降级到2.1.3来暂时解决该问题 为降级而采取的步骤: 使用$ pip uninstall amqp 。 使用$ pip install -Iv amqp==2.1.3 。 There is an open issue on github where the same OS-error has ...

C ++ / CLI中的超级基本OpenFileDialog抛出错误(Super Basic OpenFileDialog in C++/CLI is throwing error)

它要求你放: [STAThread] 在你的主要功能上。 这意味着clr应该启动单线程公寓。 Windows窗体不能在MTA(多线程单元)中工作。 进一步阅读: http : //blogs.msdn.com/b/jfoscoding/archive/2005/04/07/406341.aspx It's asking for you to put: [STAThread] on your main function. This means that clr should start a Sing...

错误消息与抛出异常C#ASP.Net(Error message vs. throwing exception C# ASP.Net)

如果是用于验证目的,我会向您推荐优秀的Fluent Validation库。 从网站引用: using FluentValidation; public class CustomerValidator: AbstractValidator<Customer> { public CustomerValidator() { RuleFor(customer => customer.Surname).NotEmpty(); RuleFor(customer => customer....

C ++从代码中的不同位置抛出相同的错误消息(C++ Throwing same error message from different places in code)

你能做的最好的事情是创建自己的异常并抛出它。 class Exception : public std::exception { public: template< typename... Args > Exception( const std::string& msg, Args... args ); virtual ~Exception() throw (); //! Overrides...

如何明确不抛出异常?(How to be explicit about NOT throwing an exception?)

这里可能有用的一种方法是改变调用您明确允许失败的代码的方式,使其看起来根本不像try / catch块。 例如,您可以编写一个执行错误报告的辅助方法,并使用表示为lambdas的操作来调用它: void InvokeFailSafe(Action action, Action<Exception> onFailure = null) { try { action(); } catch (Exception e) { if (onFailure != ...

“获取类型超出范围”错误消息抛出(“fetch type out of range” error message throwing)

尝试使用szNotes:= SQL.FieldByName('Notes')。AsWideString; try to use szNotes := SQL.FieldByName('Notes').AsWideString;

相关文章

更多

Spring Project Annotations

转自:http://www.cnblogs.com/liubin0509/p/3663807

Hibernate创建sessionFactory null

请问各位: 我在使用junit进行单元测试的时候,到实例化SessionFactory的时候不成功, ...

jpa与hibernate注解混合使用

请问jpa的注解与hibernate的注解能混合使用吗?二者是什么关系?我的意思是我用的是jpa,但是 ...

【第八章】 对ORM的支持 之 8.4 集成JPA ——跟我学spring3

JPA全称为Java持久性API(Java Persistence API),JPA是Java EE ...

刚开始学hibernate第一个小程序就出了问题,希望指点

错误信息如下: Exception in thread &quot;main&quot; org.h ...

hibernate中基于annotation(注解)的many2many双向

修改hibernate中多对多映射关系中的例子,让它基于annotation(注解)的方式。

hibernate中基于annotation(注解)的one2Many双向

在hibernate中one2Many双向中用学生和班级的关系了解了一对多的双向关联映射,现在​用注解 ...

《EJB 3.0从入门到精通》扫描版[PDF]

中文名: EJB 3.0从入门到精通 作者: 朱俊成 李有军 王俊伟 图书分类 ...

Hibernate Search(基于version3.4)--第五章Querying

Hibernate Search的第二个很重要的能力是运行Lucene queries并通过Hiber ...

Hibernate 注释方式示例

class="com656463.Employee"/&gt

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本