首页 \ 问答 \ JPA。(JPA. @Column(updatable=false) on @ManyToOne related field)

JPA。(JPA. @Column(updatable=false) on @ManyToOne related field)

在我的可审计实体中,我有字段creationUser ,我想在merge操作中不在db中更新。

这是我的实体代码:

@Column(updatable=false) 
@ManyToOne(cascade = CascadeType.MERGE)
public User creationUser;

但它给了我一个错误:

Unexpected exception
PersistenceException: [PersistenceUnit: defaultPersistenceUnit] Unable to build EntityManagerFactory
Caused by: org.hibernate.AnnotationException: @Column(s) not allowed on a @ManyToOne property: models.AreaOfMedicine.creationUser

那么如何防止更新该字段呢? 请帮忙


In my auditable entities I have field creationUser which I would like to not update in db on merge operation.

Here is my entity code:

@Column(updatable=false) 
@ManyToOne(cascade = CascadeType.MERGE)
public User creationUser;

But it gives me an error:

Unexpected exception
PersistenceException: [PersistenceUnit: defaultPersistenceUnit] Unable to build EntityManagerFactory
Caused by: org.hibernate.AnnotationException: @Column(s) not allowed on a @ManyToOne property: models.AreaOfMedicine.creationUser

So how can I prevent from updating that field? Please help


原文:https://stackoverflow.com/questions/29917148
更新时间:2022-04-01 10:04

最满意答案

它不是一个递归的函数调用,一步一步看看:

  1. terminal(stdout) - 这只是返回一个已经捕获了stdout的lambda
  2. 1的结果用lambda hello调用,它执行lambda( func(term) ),其结果被传递给terminal() ,它只返回一个lambda,如1所示。
  3. 2的结果被称为lambda world ,它与2相同,这次返回值被丢弃...

It's not a recursive function call, look at it step-by-step:

  1. terminal(stdout) - this simply returns a lambda which has captured stdout
  2. The result of 1. is called with the lambda hello, which executes the lambda (func(term)), the result of which is passed to terminal(), which simply returns a lambda as in 1.
  3. The result of 2. is called with the lambda world, which does the same as 2, this time the return value is discarded...

相关问答

更多
  • 问题的症结在于,在C ++ lambda表达式中, 隐式的 this参数将始终引用表达式的包含上下文的对象(如果存在),而不是由lambda表达式产生的函子对象。 借用匿名递归 (有时也被称为“开放递归”)的叶子,我们可以使用C ++ 14的通用lambda表达式重新引用一个显式参数来引用我们将要递归的函子: auto f = [](auto&& self, int n) -> int { return n < 2 ? 1 : n * self(/* hold on */); }; 呼叫者现在有一个新的负 ...
  • 它不是一个递归的函数调用,一步一步看看: terminal(stdout) - 这只是返回一个已经捕获了stdout的lambda 1的结果用lambda hello调用,它执行lambda( func(term) ),其结果被传递给terminal() ,它只返回一个lambda,如1所示。 2的结果被称为lambda world ,它与2相同,这次返回值被丢弃... It's not a recursive function call, look at it step-by-step: terminal ...
  • 通用的羔羊在C++14中引入。 简而言之,由lambda表达式定义的闭包类型将具有模板调用运算符,而不是C++11的lambdas的常规非模板调用运算符(当然, auto在参数列表中至少出现一次)。 所以你的例子: auto glambda = [] (auto a) { return a; }; 会使glambda成为此类型的实例: class /* unnamed */ { public: template T operator () (T a) const { ...
  • 这不是说“lambda是一个模板” - 这没有意义,lambda是一个表达式。 相反,由lambda表达式定义的闭包对象的类型具有由成员函数模板定义的重载函数调用运算符。 所以实例化点是相应调用操作符的首次使用。 换句话说,lambda [a, &b](auto x, auto y) -> R { /* ... */ }的类型如下所示: struct __lambda { __lambda(const A & __a, B & __b) : a(__a), b(__b) {} templa ...
  • 抱歉浪费你的时间。 事实证明,我需要在编译器环境的设置的“C / L”部分添加“-std = c ++ 14”标志。 我将结束这个问题。 Sorry for wasting your time. It turns out that I needed to add the "-std=c++14" flag in the 'C/L' section of the compiler environment's settings. I'll be closing this question.
  • 你需要使lambda可变: auto lambda = [value = 0]() mutable {return ++value;}; You need to make the lambda mutable: auto lambda = [value = 0]() mutable {return ++value;};
  • 你的lambda是通用的 。 这意味着这是一个伪装的模板。 情况按照模板专业化的一般规则处理。 对于每个具体的推导类型的参数x您都可以单独专注于您的功能。 所以,对于每种特定类型的x您都会得到一份y的单独副本。 但是底层机制并没有以某种方式在你的static本地化,而是你的函数的整个主体被“复制”以产生一个单独的函数实现。 你的lambda的每个专业化都会有一个单独的y副本,在第一次调用该特定专业化时,它只会被初始化一次。 情况实际上相当于一个更明确的 template void ...
  • 在运行时,您无法在两个通用lambda之间进行选择,因为您没有具体的签名来进行类型擦除。 如果你可以在编译时做出决定,你可以将类本身模板化: template class SomeClass { private: F fooCall; public: SomeClass(F&& f) : fooCall{std::move(f)} { } }; 然后,您可以创建一个辅助函数来推导F : auto makeSomeClassImpl(std::true_type) ...
  • 我已经读过lambdas可以内联而std :: bind不能内联,因为它是通过调用函数指针来实现的。 如果你将simpleAdd传递给然后绑定参数的东西,那么你是否使用bind并不重要。 你觉得lambda用func捕获了什么? 这是一个函数指针。 lambda-vs-function-pointer案例是关于编写bind(simpleAdd, 2, 3)与[] { return simpleAdd(2, 3); } [] { return simpleAdd(2, 3); } 。 或绑定一个lambda像 ...
  • 第一个错误: std::function是一个与任何lambda无关的类型。 lambda是一个匿名类型,带有operator()和一些其他已知属性。 std::function是复制构造的类型擦除类,使用Args...销毁和调用Args...并返回R 它可以用lambda构造,但不是相关类型。 由于您无法命名lambda的类型,因此使用std::function来存储它很常见。 然而,lambda不是std::function 。 std::function s的类型擦除和多态性几 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)