问题列表 - 第39732页

如何持久化具有枚举字段的对象

我在我的域模型中使用枚举,但是当我尝试将对象持久化到数据库时,我收到以下错误:

Exception in thread "main" java.lang.ClassCastException: nl.ru.cmbi.pdbeter.core.model.enums.Enum_WhifFunction cannot be cast to java.lang.String
    at org.hibernate.validator.NotEmptyValidator.isValid(NotEmptyValidator.java:36)
    at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:386)
    at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:352)
    at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:139)
    at org.hibernate.validator.event.ValidateEventListener.onPreInsert(ValidateEventListener.java:172)
    at org.hibernate.action.EntityIdentityInsertAction.preInsert(EntityIdentityInsertAction.java:142)
    at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:65)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
    at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
    at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
    at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:535)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:527)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:523)
    at nl.ru.cmbi.pdbeter.core.controller.DAO.GenericDAO.makePersistent(GenericDAO.java:73)
    at nl.ru.cmbi.pdbeter.core.controller.DAO.WhifFunctionDAO.getWhifFunctionSet(WhifFunctionDAO.java:36)
    at nl.ru.cmbi.pdbeter.core.controller.DAO.LoggedErrorWhifDAO.updateWhifFunctionSet(LoggedErrorWhifDAO.java:42)
    at nl.ru.cmbi.pdbeter.whifclient.controller.WhifFunctionsUpdater.executeWhifFunctionsByAccessionCode(WhifFunctionsUpdater.java:93)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy31.executeWhifFunctionsByAccessionCode(Unknown Source) …

java persistence hibernate enumeration

5
推荐指数
1
解决办法
2493
查看次数

在linq中,如何从列表中取出特定参数并构建不同类型的新列表?

我是linq的新手.到目前为止,我一直主要使用这样的linqTOsql : MyRepository.Mytable.Where(x => x.id == 2).

我想知道如何从这种类型的查询中获取一个列表,并将一个特定的参数放入一个新的简单列表,如List<long>.

所以我得到了这样的记录:

List<Entry2Cats> e2c = genesisRepository.Entry2Cats.Where( x => x.streamEntryID == id).ToList()
Run Code Online (Sandbox Code Playgroud)

我希望获得每个项目的类别ID参数,e2c以便我可以将其移动到List<long>.

显然,这可以通过以下方式简单地完成foreach:

        List<Entry2Cats> e2c = genesisRepository.Entry2Cats
                               .Where(x => x.streamEntryID == id)
                               .ToList();
        List<long> e2cCatIDs = new List<long>();

        foreach (Entry2Cats item in e2c)
        {
            e2cCatIDs.Add(item.catID);
        }
Run Code Online (Sandbox Code Playgroud)

这可以用linq完成吗?如果可以的话,我是否应该打扰它或者是foreach同样好的?

c# linq foreach

2
推荐指数
1
解决办法
131
查看次数

如何在git中找到"丢失"的代码

曾几何时,一个坏人从我们的GIT仓库管理的源代码中删除了一个常量.

到目前为止,没有人注意到这个问题.

然而,我想弄清楚这个常数在哪个提交中消失了,坏人是谁.

我只知道它的名字FOOBAR.

一些更好的方法是git blame --reverse什么?

git version-control

8
推荐指数
1
解决办法
1644
查看次数

.net windows服务本地应用程序数据与普通应用程序不同

在普通的控制台应用程序我有这个

Environment.SpecialFolder.LocalApplicationData是 C:\Users\Simon\AppData\Local\

在Windows服务中

Environment.SpecialFolder.LocalApplicationDataC:\Windows\system32\config\systemprofile\AppData\Local\

如何在两种类型的应用程序中指定相同的路径?

c# windows-services

11
推荐指数
1
解决办法
5045
查看次数

使用<ctime>和指令重新排序进行基准测试

到目前为止,我一直在使用传统的方法来对并发方法进行基准测试,即测量多次运行的持续时间:

template <typename Functor>
double benchmark(Functor const& f, size_t nbRuns)
{
  if (nbRuns == 0) { return 0.0; }

  f(); // Initialize before measuring, I am not interesting in setup cost

  time_t begin = time(0);
  for (size_t i = 0; i != nbRuns; ++i) { f(); }
  time_t end = time(0);

  return difftime(end, begin);
}
Run Code Online (Sandbox Code Playgroud)

在我遇到这个问题之前看起来一切都很好和花花公子:优化掉"while(1);" 在C++ 0x中循环.

让我感到不同寻常的是,允许编译器在循环之前执行输出......我突然想知道:

什么阻止编译器time_t end = time(0);在循环之前执行?

因为如果它这样做,那将以某种方式拧紧我的小基准代码.

虽然我们在这里,但如果在这种情况下可能发生重新排序:

怎么能阻止它呢?

除了C++之外我无法想到相关标签,如果有人认为我错过了它,请随意添加它

c++ c++11

6
推荐指数
1
解决办法
436
查看次数

c ++在try和catch时返回值

嗨,当警告"控制到达无效功能的结束"时,我该怎么办?我的重载运算符已尝试捕获并returns *this ;在try范围内.

我正在使用Eclipse,G ++是编译器,UBUNTU是linux

NNmatrix & operator*=(const NNmatrix<T> &mtrxB)
        {
            // A=2*3 B=3*4  return C=2*4
            const UINT aRows = this->size1();
            const UINT aCols = this->size2();
            const UINT bRows = mtrxB.size1();
            const UINT bCols = mtrxB.size2();
            try
            {
                // if cols of first(this) matrix == rows of second matrix
                if (aCols != bRows) throw bad_alloc();
                const UINT cRows = aRows;// = rows of first matrix
                const UINT cCols = bCols; // = cols of second matrix
                NNmatrix mtrxC(cRows, …
Run Code Online (Sandbox Code Playgroud)

c++ exception try-catch return-value

1
推荐指数
1
解决办法
6354
查看次数

for循环中的Python默认变量

我想知道Python是否具有在for循环中将数据存储在默认变量中的概念.

例如,在perl中,等价物如下

foreach (@some_array) {
    print $_
}
Run Code Online (Sandbox Code Playgroud)

谢谢,德里克

python variables for-loop

3
推荐指数
1
解决办法
1302
查看次数

php查找字符串

如何找到这个字符串:

132,139,150,166,176
Run Code Online (Sandbox Code Playgroud)

在这一个?:

132,139,150,166,176,131,140,151,165,175
Run Code Online (Sandbox Code Playgroud)

php string string-search

6
推荐指数
2
解决办法
4950
查看次数

等待定义时间的窗口消息

我正在用winapi编程.如何在指定时间内等待消息?如果没有消息,我可以做另一项任务.我无法使用Sleep,因为窗口回调程序将被延迟.

while (true){
    ...//wait a message for 30 miliseconds
    GetMessage(&message, hwnd, 0, 0) ) or PeekMessage(&message, hwnd, 0, 0, PM_REMOVE)
    ...
    if ( no_message ){
        call_a_function();
    } else {
        if (finish)
            break;
        TranslateMessage(&message);
        DispatchMessage(&message);
        ...//set to wait 30 minus elapsed time 
    }
}
Run Code Online (Sandbox Code Playgroud)

windows winapi loops window timer

2
推荐指数
1
解决办法
1067
查看次数

总和为S的最小硬币数

给出N个硬币的列表,它们的值(V1,V2,...,VN)和总和S.找到其总和为S的最小硬币数量(我们可以使用一种类型的硬币.我们想要),或者报告说不可能以这样的方式选择硬币,它们总结为S.

我试着理解动态编程,还没弄明白.我不明白给出的解释,所以也许你可以给我一些提示如何编程这个任务?没有代码,只是我应该开始的想法.

谢谢.

algorithm dynamic dynamic-programming task

17
推荐指数
2
解决办法
4万
查看次数