Basic CRUD many-to-one operation


#1

hi, i am new to axelor,
i have a model Vehicle Model that many of it belongs to one vehicle manufacturer
this is VehicleManufacturer Model:

<entity name="VehicleManufacturer" cachable="true">

    <string name="name" title="Name" required="true" />

    <one-to-one name="logo"  title="Logo" ref="com.axelor.meta.db.MetaFile" required="true" />

</entity>

andi this is VehicleModel:

<entity name="VehicleModel" cachable="true">

	<string name="name" title="Name" required="true"/>

	<many-to-one name="vehicleManufacturer" ref="VehicleManufacturer" title="Manufacturer"/>

	<one-to-one name="image"  title="Image" ref="com.axelor.meta.db.MetaFile" required="true" />

	<one-to-many name="region" ref="ModelsRegion" title="Region"/>

</entity>

but when trying the create form it throws a Type mismatch Exception :

so please someone help me


#2

com.axelor.meta.db.MetaFile needs to be a fully qualified path to the VehicleModel class

ALSO, you might consider using fully qualified path to VehicleManufacturer class in your many-to-one mapping


#3

com.axelor.meta.db.MetaFile needs to be a fully qualified path to the VehicleModel class

Can you explain more


#4

Something like :
com.axelor.your_module_name.db.VehicleModel

Another way :
Find where the VehicleModel file has been generated in. This needs to be the package of the generated file.


#5

thank you, i am tryig it now.


#6

not solved, the same error again,
note thatwhen i don’t fill the many-to-one field(VehicleManufacturer) the save works fine


#7

can you confirm that you don’t try to use an updated domain (vehicleManufacturer field has almways been a ref to VehicleManufacturer and not a selction of another package ?

<module name="mymodule" package="com.mymodule.db" />

<entity name="VehicleManufacturer">
	<string name="name" title="Name" required="true" />
	<many-to-one name="logo"  title="Logo" ref="com.axelor.meta.db.MetaFile" required="true" />
</entity>
<entity name="ModelsRegion">
	<string name="name" title="Name" required="true" />
</entity>
<entity name="VehicleModel">
	<string name="name" title="Name" required="true"/>
    	<many-to-one name="vehicleManufacturer" ref="com.mymodule.db.VehicleManufacturer" title="Manufacturer"/>
    	<many-to-one name="image"  title="Image" ref="com.axelor.meta.db.MetaFile" required="true" />
    	<one-to-many name="region" ref="com.mymodule.db.ModelsRegion" title="Region"/>
</entity>
</module>

As specified by @prashant you have to set the full domain name inside the “ref” attribute. The full domain name consist of the java package which is module:package + “.” + entity:name.

I also advise you to avoid using “cachable=true” to avoid any refresh problems.


#8

yeah i confirm it, i did just what you have in the example but still not working!!,
also i know that it works because in the view i show the VehicleManufacturer field with a selectTag attribute and it works, it shows me the already present manufacturers but when selection one of 'em and hit save it shows that damn error


#9

@omarAjmi : please paste the stacktrace - as text, not as a screenshot.
Also, the cause of the problem.


#10

could you also provide your form xml maybe the mistake is inside it ?


#11

am sorry for the late reply i was sick,
anyhow this is the form xml

<form name="vehicle-model-form" title="Vehicles Models" model="com.mymodule.db.VehicleModel"  width="large">
	   <panel>

		   <panel colSpan="2">

			   <field name="image" widget="Image" colSpan="12"/>

		   </panel>

		   <panel colSpan="6" itemSpan="12">

			   <field name="name" />

			   <field name="vehicleManufacturer" widget="TagSelect"/>

			   <field name="region" widget="TagSelect"/>

		   </panel>

	   </panel>
   </form>

and this is the stack trace:

java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.axelor.db.mapper.Mapper.set(Mapper.java:372)
at com.axelor.db.JPA._edit(JPA.java:411)
at com.axelor.db.JPA.edit(JPA.java:292)
at com.axelor.rpc.Resource.save(Resource.java:870)
at com.axelor.rpc.ResponseInterceptor.invoke(ResponseInterceptor.java:55)
at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:70)
at com.axelor.web.service.RestService.save(RestService.java:158)
at com.axelor.rpc.RequestFilter.invoke(RequestFilter.java:55)
at com.axelor.rpc.ResponseInterceptor.invoke(ResponseInterceptor.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:294)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:248)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:235)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:398)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:205)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:228)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:89)
at com.axelor.db.tenants.AbstractTenantFilter.doFilter(AbstractTenantFilter.java:67)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
at org.apache.shiro.guice.web.SimpleFilterChain.doFilter(SimpleFilterChain.java:44)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at com.axelor.auth.AuthFilter.doFilterInternal(AuthFilter.java:78)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.guice.web.SimpleFilterChain.doFilter(SimpleFilterChain.java:41)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
at com.axelor.app.internal.AppFilter.doFilter(AppFilter.java:93)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
at com.google.inject.persist.PersistFilter.doFilter(PersistFilter.java:91)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
at com.axelor.db.tenants.AbstractTenantFilter.doFilter(AbstractTenantFilter.java:67)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
at com.axelor.web.servlet.CorsFilter.doFilter(CorsFilter.java:132)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:82)
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:120)
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:135)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

#12

@omarAjmi
You can’t add widget="TagSelect" on a the M2O vehicleManufacturer field.
TagSelect widget can only be used on M2M.

Remove the widget and you will be able to save the record.

Regards


#13

thank you so much for the help but don’t you think you should put that in the DOCs!!!,
it’s very poor and don’t cover much


#14

Without wanting to defend Axelor, there are thousands of features and it’s not easy to make them all appear in the doc. That’s why there is the community. Like I done, the better way is to deep inside the ABS/ADK source code to take examples.