• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ids for this class must be manually assigned before calling save(): tblName

New Here ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

Hoy folks,

 

Long time lurker first time caller. 

 

I've hit an issue with ColdFusion ORM that I just can't figure out. Here's the situation.

 

1) I have a database procedure that I use to create tables with a number of columns that are common to all the tables. These columns are mapped to the persistent component.

 

2) The code to generate the keys looks like this (wod= word of the day):

CREATE TABLE [dbo].[tblName](
[idx] [int] IDENTITY(1,1) NOT NULL,
[id] [varchar](36) PRIMARY KEY NOT NULL,

 

ALTER TABLE [dbo].[tblName] ADD CONSTRAINT [DF_tblName_id] DEFAULT (newid()) FOR [id]

 

3) The rest of the columns mapped to given entity are generated by ORM.

 

4) The code for mapping these fields is...

property name="idx" fieldtype="column" ormtype="int" generated="insert" setter="false";
property name="id" fieldType="id" length=36 generated="insert" setter="false";

 

5) My goal is to get the id property to be populated on save() from the database.

 

6) I get this error, no matter what combination of attributes I try for the id property:

 

"ids for this class must be manually assigned before calling save(): tblName"

 

I'm at a total loss. Can you please help a man out?

 

Thanks much,

 

JH

Views

8.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

For context:

  • What is your ColdFusion version and update level?
  • What is the full error message that you get in ColdFusion's logs, particularly in hebernatesql.log?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

By the way, I ask for your version because, in recent ColdFusion versions, you have to do an ORM save within a transaction.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

Oh, I see something else just now. It seems to me that id and idx amount to duplication. Something else I see is that id is a Varchar, yet you configure it with auto-insert.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

Thanks so much for the replies, BKBK.

 

In order...

 

CF Version: 
2018,0,11,326016

 

More of the error message:
ids for this class must be manually assigned before calling save(): wod
Root cause :org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): wod
Stack Trace
at cfwodController2ecfc1045076657$funcADDWOD.runFunction(<!---removed--->/wwwroot/controllers/wodController.cfc:113) at cfwodController2ecfc1045076657$funcSHOW.runFunction(<!---removed--->/wwwroot/controllers/wodController.cfc:21) at cfindex2ecfm1935357928.runPage(<!---removed--->/wwwroot/admin/test/index.cfm:13) at cfApplication2ecfc27338588$funcONREQUEST.runFunction(<!---removed--->/wwwroot/Application.cfc:128) at cfwodController2ecfc1045076657$funcADDWOD.runFunction(<!---removed--->/wwwroot/controllers/wodController.cfc:113) at cfwodController2ecfc1045076657$funcSHOW.runFunction(<!---removed--->/wwwroot/controllers/wodController.cfc:21) at cfindex2ecfm1935357928.runPage(<!---removed--->/wwwroot/admin/test/index.cfm:13) at cfApplication2ecfc27338588$funcONREQUEST.runFunction(<!---removed--->/wwwroot/Application.cfc:128)

org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): wod
at org.hibernate.id.Assigned.generate(Assigned.java:33)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:105)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:97)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:658)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:650)
at coldfusion.orm.hibernate.SessionWrapper.saveOrUpdate(SessionWrapper.java:413)
at coldfusion.orm.hibernate.HibernatePersistenceManager.save(HibernatePersistenceManager.java:151)
at coldfusion.orm.hibernate.HibernatePersistenceManager.save(HibernatePersistenceManager.java:131)
at coldfusion.orm.ORMUtils.entitySave(ORMUtils.java:201)
at coldfusion.runtime.CFPage.EntitySave(CFPage.java:12372)
at cfwodController2ecfc1045076657$funcADDWOD.runFunction(<!---removed--->wwwroot\controllers\wodController.cfc:113)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:554)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:485)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:448)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:399)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:372)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:288)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4175)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:4155)
at cfwodController2ecfc1045076657$funcSHOW.runFunction(<!---removed--->wwwroot\controllers\wodController.cfc:21)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:554)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:485)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:448)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:399)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:372)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:288)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:830)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:613)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:438)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3627)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3604)
at cfindex2ecfm1935357928.runPage(<!---removed--->wwwroot\admin\test\index.cfm:13)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:262)
at coldfusion.tagext.lang.IncludeTag.handlePageInvoke(IncludeTag.java:735)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:565)
at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:4329)
at cfApplication2ecfc27338588$funcONREQUEST.runFunction(<!---removed--->wwwroot\Application.cfc:128)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:554)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:485)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:448)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:399)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:372)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:288)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:830)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:613)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:438)
at coldfusion.runtime.AppEventInvoker.invoke(AppEventInvoker.java:115)
at coldfusion.runtime.AppEventInvoker.onRequest(AppEventInvoker.java:308)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:550)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:43)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:162)
at coldfusion.filter.IpFilter.invoke(IpFilter.java:45)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:96)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:60)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
at coldfusion.CfmServlet.service(CfmServlet.java:226)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:311)
at jdk.internal.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:282)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:279)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/javax.security.auth.Subject.doAsPrivileged(Subject.java:550)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:314)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:170)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:225)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:47)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:149)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:145)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:46)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:47)
at jdk.internal.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:282)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:279)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/javax.security.auth.Subject.doAsPrivileged(Subject.java:550)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:314)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:191)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:47)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:149)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:145)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at jdk.internal.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:282)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:279)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/javax.security.auth.Subject.doAsPrivileged(Subject.java:550)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:314)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:191)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:47)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:149)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:145)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)
at com.seefusion.Filter.doFilter(Filter.java:49)
at com.seefusion.SeeFusion.doFilter(SeeFusion.java:1500)
at jdk.internal.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:282)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:279)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/javax.security.auth.Subject.doAsPrivileged(Subject.java:550)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:314)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:253)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:191)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:47)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:149)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:145)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:359)
at org.apache.coyote.ajp.AjpProcessor.service(AjpProcessor.java:459)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:888)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834)

 

Hibernate Logs

I use commercial hosting. I'll be honest, I'm not sure where to find those logs in their Control Panel. 

 

Idx and Id

Yeah. I get that's confusing and it may be the problem. What I want to do is have an Idx column that is int and auto-incremented becuase it's just so darn convient to have. But, the PK Id column itself is [varchar](36) defaulted to (newid()) for security reasons... essencially if the PK is exposed, I don't want the others to be guessable. I chose [varchar](36) becuase it will accomodate a UniqueIdentifier, but that may be a wrong decision. 

 

Again, the help is much appreciated. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2021 Apr 27, 2021

Copy link to clipboard

Copied

One last note. Now that I've given the issue a bit more thought, I'm not committed to having the PK generated by the database. It can definitely come from the code. What I'm committed to is having the PK be a uniqueidentifier. Same with the idx column. If ORM can generate an incremental int for each entry which is not the PK, that's fine too. I've tried the hibernate documentation, but I can't seem to find incrementing non-PK fields. But, I'm very new to ORM and Hibernate. If it wasn't for the ColdFusion Certification Training, I would have done this the old way!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2021 May 11, 2021

Copy link to clipboard

Copied

Did you solve the problem? If not, you could add a generator to the primary key. That is, you could try something like:

 

property name="idx" fieldtype="column" ormtype="int" setter="false";
property name="id" fieldType="id" length="36" generator="identity" setter="false";

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

LATEST

Thanks so much for your reply. In the end that's what I did. I'd still like it work with generated="insert" and let SQL Server generate a unique id. But, in order to keep moving, I dropped the Idx field and I'm using a guid for the id. 

 

Some day, I'll dig into the Hibernate documentation. I just don't have the time (or energy 😉 right now.

 

Best,

J.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation