在Alfresco创建类SQL表模型:无继承内置模型的城市模型是否可行?
Great question! Let's break this down clearly based on how you plan to use your city model in Alfresco:
Short Answer
You don't have to inherit from cm:content or cm:folder (the common built-in content/folder models), but there's a key caveat if you want your city model to exist as a standalone node in Alfresco.
Detailed Breakdown
1. If you need the city model as a standalone, usable node
Alfresco requires all nodes that can be created, stored, and managed in the repository to ultimately inherit from cm:cmobject—this is the core base type that provides essential system metadata (like a unique system-generated UUID, creation timestamp, owner, etc.). Without this inheritance, Alfresco can't properly handle the node in its repository system.
That said, you don't need to inherit from cm:content or cm:folder—you can just inherit directly from cm:cmobject and only add your custom id and city name properties. Here's a sample model definition for this scenario:
<model name="city:model" xmlns="http://www.alfresco.org/model/dictionary/1.0"> <description>City Entity Model</description> <author>Your Name</author> <version>1.0</version> <imports> <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/> <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/> </imports> <namespaces> <namespace uri="http://yourcompany.com/model/city/1.0" prefix="city"/> </namespaces> <types> <type name="city:city"> <title>City</title> <description>City entity with custom ID and name</description> <!-- Inherit only from the core node base type, not content/folder --> <parent>cm:cmobject</parent> <properties> <property name="city:id"> <title>City ID</title> <description>Custom unique identifier for the city</description> <type>d:text</type> <mandatory>true</mandatory> <!-- Add a unique constraint to ensure no duplicate IDs --> <constraints> <constraint name="city:uniqueCityId" type="d:unique"/> </constraints> </property> <property name="city:name"> <title>City Name</title> <description>Name of the city</description> <type>d:text</type> <mandatory>true</mandatory> </property> </properties> </type> </types> </model>
This gives you a clean node type with exactly your two custom properties, plus the minimal system metadata from cm:cmobject—no extra content/folder-related baggage.
2. If you only need the model as a data structure (not a standalone node)
You can create a type that doesn't inherit from any built-in models at all. However, this type can't be instantiated as a standalone node—it can only be used as part of another node's properties or associations (like a complex data type). Here's an example:
<model name="city:model" xmlns="http://www.alfresco.org/model/dictionary/1.0"> <description>City Data Structure</description> <author>Your Name</author> <version>1.0</version> <imports> <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/> </imports> <namespaces> <namespace uri="http://yourcompany.com/model/city/1.0" prefix="city"/> </namespaces> <types> <type name="city:cityData"> <title>City Data</title> <description>City data structure with no built-in inheritance</description> <!-- No parent specified = no inheritance from built-in models --> <properties> <property name="city:id"> <title>City ID</title> <type>d:text</type> <mandatory>true</mandatory> </property> <property name="city:name"> <title>City Name</title> <type>d:text</type> <mandatory>true</mandatory> </property> </properties> </type> </types> </model>
This is only useful if you're embedding city data into other nodes (e.g., a company:office node that has a city:cityData property), but not if you want to manage cities as separate entities in Alfresco.
Final Takeaway
If you want cities to be standalone, manageable nodes in Alfresco:
- You must inherit from
cm:cmobject(non-negotiable for repository nodes) - You do NOT need to inherit from
cm:contentorcm:folder
If you just need a reusable data structure:
- You can skip all built-in inheritance, but this has limited use cases.
内容的提问来源于stack exchange,提问作者yussenn

