Data Model Fundamentals
Overview
- What you’ll learn: The core database tables, naming conventions, standard column patterns, key entities, and the client-organization data isolation model that form the foundation of every iDempiere system.
- Prerequisites: Lesson 6 – Working with Windows and Tabs
- Estimated reading time: 22 minutes
Introduction
Every enterprise resource planning system is, at its core, a structured collection of database tables and the relationships between them. iDempiere’s data model has been refined over two decades, evolving from Compiere through ADempiere to its current form. Understanding this data model is essential for anyone who wants to go beyond basic data entry and truly comprehend how the system works.
In this lesson, you will learn the naming conventions that make iDempiere’s hundreds of tables immediately recognizable, the standard columns that appear on every table, the key entities that represent fundamental business concepts, and the data isolation model that enables multi-tenant operation. This knowledge forms the foundation for everything that follows, from business partner management to financial posting to custom development.
Table Naming Conventions
iDempiere organizes its tables into logical groups using prefix conventions. The prefix of a table name immediately tells you which functional area it belongs to. Knowing these prefixes allows you to locate tables quickly and understand their purpose at a glance.
Core Table Prefixes
| Prefix | Module | Examples |
|---|---|---|
AD_ |
Application Dictionary / System Administration | AD_Table, AD_Column, AD_Window, AD_User, AD_Role, AD_Client, AD_Org |
C_ |
Core Business (Partners, Orders, Invoices, Payments, Accounting) | C_BPartner, C_Order, C_Invoice, C_Payment, C_AcctSchema, C_Currency |
M_ |
Material Management (Products, Warehouses, Inventory) | M_Product, M_Warehouse, M_InOut, M_Inventory, M_Locator, M_PriceList |
GL_ |
General Ledger | GL_Journal, GL_JournalLine, GL_JournalBatch, GL_Category |
PP_ |
Production Planning / Manufacturing | PP_Order, PP_Product_BOM, PP_Product_Planning |
I_ |
Import (temporary staging tables) | I_BPartner, I_Product, I_Order, I_Invoice, I_GLJournal |
T_ |
Temporary (session-based work tables) | T_Report, T_Aging, T_TrialBalance |
PA_ |
Performance Analysis | PA_Goal, PA_Measure, PA_Report |
R_ |
Request / Service Management | R_Request, R_RequestType, R_Category |
S_ |
Service / Resources | S_Resource, S_ResourceType, S_TimeExpense |
W_ |
Web Store | W_Store, W_Click, W_Basket |
HR_ |
Human Resources / Payroll | HR_Employee, HR_Concept, HR_Process |
A_ |
Asset Management | A_Asset, A_Asset_Group, A_Depreciation |
When you encounter an unfamiliar table, the prefix immediately narrows down its functional area. A table starting with M_ relates to material management, one starting with C_ relates to core business processes, and so on.
Line Tables
As discussed in the previous lesson, many header tables have corresponding line tables. The naming convention is straightforward: append Line to the header table name. C_Order has C_OrderLine, C_Invoice has C_InvoiceLine, and GL_Journal has GL_JournalLine.
Custom Table Prefixes
When creating custom tables, you should use your own prefix to avoid conflicts with core tables and with other customizations. Common approaches include using a two-letter company abbreviation (e.g., XX_) or a project-specific prefix. This prefix should align with your custom entity type registered in the Application Dictionary.
Standard Column Patterns
One of the most consistent aspects of iDempiere’s data model is the set of standard columns that appear on virtually every table. These columns enable core system functionality like multi-tenancy, auditing, and soft deletion.
Mandatory Standard Columns
| Column | Type | Purpose |
|---|---|---|
AD_Client_ID |
Numeric (FK) | Identifies which client (tenant) owns this record |
AD_Org_ID |
Numeric (FK) | Identifies which organization within the client owns this record |
IsActive |
Char(1) | Soft delete flag: Y = active, N = deactivated (not physically deleted) |
Created |
Timestamp | When the record was first created |
CreatedBy |
Numeric (FK to AD_User) | Which user created the record |
Updated |
Timestamp | When the record was last modified |
UpdatedBy |
Numeric (FK to AD_User) | Which user last modified the record |
These seven columns are present on every regular data table in iDempiere. The system’s persistence layer (the PO — Persistent Object — framework) automatically manages Created, CreatedBy, Updated, and UpdatedBy, so developers and users never need to populate them manually.
Primary Key Convention
Every table’s primary key column follows a strict naming convention: TableName_ID. The table C_Order has the primary key C_Order_ID. The table M_Product has M_Product_ID. The table AD_User has AD_User_ID. This convention is not merely a suggestion; the Application Dictionary and the Java model layer depend on it for automatic foreign key resolution, link column detection, and reference lookups.
Primary key values are generated from database sequences. Each table has its own sequence (e.g., C_Order_Seq), and the system retrieves the next value when creating a new record.
UUID Columns
In addition to the numeric primary key, iDempiere tables include a UUID (Universally Unique Identifier) column following the pattern TableName_UU. For example, C_Order_UU stores a UUID like a1b2c3d4-e5f6-7890-abcd-ef1234567890. UUIDs serve several important purposes:
- Cross-system identification: Unlike numeric IDs, which are sequence-dependent and can differ between systems, UUIDs are globally unique. This makes them essential for data migration, synchronization, and 2Pack packaging.
- REST API references: When exposing data through web services, UUIDs provide stable, system-independent identifiers.
- Replication: Multi-site environments use UUIDs to match records across servers.
Foreign Key Conventions
Foreign keys in iDempiere follow the same naming pattern as primary keys. If a table has a column named C_BPartner_ID, it is a foreign key reference to the C_BPartner table. This consistency means you can determine the referenced table from any foreign key column name by removing the _ID suffix. The Application Dictionary’s Table Direct reference type exploits this convention to automatically resolve lookups without additional configuration.
Key Entities
iDempiere’s data model includes hundreds of tables, but a core set of entities forms the backbone of the entire system. Understanding these key entities is essential for comprehending how business data flows through iDempiere.
AD_Client: The Tenant
At the highest level, AD_Client represents a tenant in iDempiere’s multi-tenant architecture. Each client is a completely isolated business entity with its own chart of accounts, business partners, products, and transactions. A single iDempiere installation can host multiple clients, each unaware of the others’ data.
Every iDempiere installation has at least two clients:
- System (AD_Client_ID = 0): Contains system-level configuration, dictionary definitions, and shared reference data. Regular users never work directly in the System client.
- Your company client (e.g., AD_Client_ID = 11): Contains your actual business data. This is where users log in and perform daily operations.
AD_Org: The Organization
Within a client, AD_Org represents an organizational unit. Organizations can model divisions, departments, branches, legal entities, or any other structural unit your business requires. The organization hierarchy enables:
- Data segregation: Records can be assigned to specific organizations, restricting visibility.
- Role-based access: Users can be granted access to specific organizations, ensuring they only see relevant data.
- Financial reporting: Organizations can have their own accounting schemas for consolidated or segmented reporting.
Every client has a special organization with AD_Org_ID = 0 (often labeled with an asterisk *). Records assigned to org 0 are considered shared across all organizations within the client. Reference data like payment terms, currencies, and tax rates are typically assigned to org 0.
C_BPartner: Business Partner
The C_BPartner table is one of the most central entities in iDempiere. It represents any external party your organization does business with: customers, vendors, employees, or any combination thereof. A single business partner record can simultaneously be a customer, a vendor, and an employee. Business partners will be covered in depth in the next lesson.
M_Product: Product
M_Product represents items, services, resources, or expenses that can be bought, sold, manufactured, or stocked. Products are categorized by product type (Item, Service, Resource, Expense), and items can be further classified by product category for reporting and accounting. Key related tables include:
M_Product_Category: Grouping for accounting defaults and reporting.M_Product_PO: Purchasing information (vendor, vendor product number, list price).M_ProductPrice: Prices on specific price lists.M_Storage/M_StorageOnHand: Inventory quantities by warehouse locator.
C_Order: Sales and Purchase Orders
C_Order is the universal order table used for both sales orders and purchase orders. The IsSOTrx flag distinguishes between the two: Y for sales, N for purchasing. This unified design means the same infrastructure handles both sides of the transaction, with the Application Dictionary’s display logic and window configuration adapting the user interface accordingly.
C_Invoice: Invoices
C_Invoice manages both customer invoices (Accounts Receivable) and vendor invoices (Accounts Payable), again using IsSOTrx to distinguish direction. Invoices link to orders, shipments, and payments, forming the complete document chain.
M_InOut: Shipments and Material Receipts
M_InOut handles physical movement of goods, covering both outbound shipments to customers and inbound receipts from vendors. The IsSOTrx flag indicates direction. Each M_InOutLine references the product, quantity, and warehouse locator.
C_Payment: Payments
C_Payment records incoming payments from customers and outgoing payments to vendors. Payments link to invoices through the allocation mechanism (C_AllocationHdr / C_AllocationLine), which supports partial payments, overpayments, and cross-invoice allocation.
The Data Isolation Model
iDempiere’s multi-tenant data isolation is one of its most important architectural features. Understanding this model is crucial for administrators and developers alike.
Three Levels of Data Scope
Data in iDempiere exists at three levels of visibility:
| Level | AD_Client_ID | AD_Org_ID | Visibility |
|---|---|---|---|
| System | 0 | 0 | Shared across all clients (dictionary, reference data) |
| Client-wide | Your Client | 0 | Shared across all organizations within the client |
| Organization-specific | Your Client | Specific Org | Visible only to users with access to that organization |
How Data Isolation Works
When a user logs in, they select a client, a role, and an organization. Every database query the system executes automatically includes a filter on AD_Client_ID, and most queries also filter on AD_Org_ID based on the user’s role permissions. This filtering happens at the framework level, deep within the persistence and query infrastructure, so it is transparent to the application code above it.
The practical effect is that:
- A user logged into Client A can never see data belonging to Client B, regardless of SQL queries or API calls.
- A user restricted to Organization “East Division” cannot see records belonging to “West Division.”
- System-level records (Client 0, Org 0) are visible to all clients as read-only reference data.
- Client-wide records (Org 0 within a client) are visible to all organizations within that client.
Shared Data from the System Client
The System client (AD_Client_ID = 0) holds data that is common across all tenants. This includes:
- Application Dictionary definitions (AD_Table, AD_Column, AD_Window, etc.)
- System-level reference data (countries, currencies, languages)
- Default chart of accounts templates
When a new client is created using the Initial Client Setup process, it copies relevant reference data from the System client and creates client-specific versions where needed.
The Organization Hierarchy
Organizations in iDempiere can be structured in a hierarchy using the AD_Tree mechanism. A typical multi-branch company might have:
Company (Client)
├── Headquarters (Org)
│ ├── Finance Department (Org)
│ └── HR Department (Org)
├── East Region (Org)
│ ├── New York Office (Org)
│ └── Boston Office (Org)
└── West Region (Org)
├── Los Angeles Office (Org)
└── San Francisco Office (Org)
Users with access to a parent organization can typically see data from all child organizations, depending on the role’s IsAccessAllOrgs setting and the org access configuration. This hierarchy enables both granular data isolation and consolidated reporting.
Understanding Record IDs
Every record in iDempiere is identified by its numeric ID (the TableName_ID column). These IDs are critical for understanding data relationships. When you see C_BPartner_ID = 119 in an order record, you know it references business partner record 119 in the C_BPartner table.
Important characteristics of record IDs:
- Sequence-generated: IDs are assigned automatically from database sequences. They are not user-configurable.
- System-specific: The same business partner might have
C_BPartner_ID = 119on one server andC_BPartner_ID = 5023on another. Never hard-code IDs in customizations. - Reserved ranges: IDs below a certain threshold (typically 1,000,000) are reserved for standard seed data. Custom records use IDs above this threshold.
- Zero means not set: An ID value of 0 typically means “not specified” and may have special behavior (e.g., AD_Org_ID = 0 means shared).
Best practice: When writing SQL queries or customizations, always reference records by their UUID or by a unique key field (like Value) rather than by numeric ID. This ensures your code works correctly across different environments.
Putting It All Together: The Document Flow
To see how these entities work together, consider a simple sales cycle:
- A Business Partner (
C_BPartner) is created as a customer. - A Sales Order (
C_Order,IsSOTrx='Y') is created for that customer, with line items referencing Products (M_Product). - The order is completed, generating a Shipment (
M_InOut) that reduces inventory. - An Invoice (
C_Invoice) is generated from the order or shipment. - A Payment (
C_Payment) is received and allocated against the invoice.
Each of these documents carries AD_Client_ID and AD_Org_ID, linking them to their tenant and organizational context. The foreign keys (like C_BPartner_ID on C_Order, C_Order_ID on C_OrderLine) weave these entities into a traceable chain that supports reporting, auditing, and business intelligence.
Key Takeaways
- Table prefixes (AD_, C_, M_, GL_, PP_, I_, T_) immediately identify the functional module a table belongs to.
- Seven mandatory standard columns (AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy) appear on every table and enable multi-tenancy, soft deletion, and audit tracking.
- Primary keys follow the TableName_ID convention, and foreign keys use the same name as the referenced table’s primary key.
- UUID columns (TableName_UU) provide system-independent record identification for migration, replication, and web services.
- AD_Client provides tenant isolation; AD_Org provides organizational data segregation within a tenant.
- Data exists at three scopes: System (shared globally), Client-wide (shared within a tenant), and Organization-specific (restricted to an org).
- Key entities (C_BPartner, M_Product, C_Order, C_Invoice, M_InOut, C_Payment) form the document chain that drives all business processes.
What’s Next
In the next lesson, Business Partner Management, you will take a deep dive into the C_BPartner entity, exploring how customers, vendors, and employees are configured, how addresses and contacts are managed, and how business partners connect to the transactional document chain.
繁體中文
概述
- 您將學到:構成每個 iDempiere 系統基礎的核心資料庫資料表、命名慣例、標準欄位模式、關鍵實體,以及用戶端—組織資料隔離模型。
- 先修課程:第 6 課 – 使用視窗與頁籤
- 預估閱讀時間:22 分鐘
簡介
每個企業資源規劃系統的核心,本質上就是一組結構化的資料庫資料表以及它們之間的關聯。iDempiere 的資料模型歷經二十多年的精煉,從 Compiere 到 ADempiere 再演進到目前的形式。對於任何想要超越基本資料輸入、真正理解系統運作方式的人來說,理解這個資料模型是不可或缺的。
在本課程中,您將學習讓 iDempiere 數百個資料表一目了然的命名慣例、出現在每個資料表上的標準欄位、代表基本商業概念的關鍵實體,以及實現多租戶運作的資料隔離模型。這些知識構成了後續所有內容的基礎,從業務夥伴管理到財務過帳再到自訂開發。
資料表命名慣例
iDempiere 使用前綴慣例將資料表組織成邏輯群組。資料表名稱的前綴能立即告訴您它所屬的功能模組。了解這些前綴可以讓您快速定位資料表,並一眼理解其用途。
核心資料表前綴
| 前綴 | 模組 | 範例 |
|---|---|---|
AD_ |
應用程式字典 / 系統管理 | AD_Table, AD_Column, AD_Window, AD_User, AD_Role, AD_Client, AD_Org |
C_ |
核心業務(夥伴、訂單、發票、付款、會計) | C_BPartner, C_Order, C_Invoice, C_Payment, C_AcctSchema, C_Currency |
M_ |
物料管理(產品、倉庫、庫存) | M_Product, M_Warehouse, M_InOut, M_Inventory, M_Locator, M_PriceList |
GL_ |
總帳 | GL_Journal, GL_JournalLine, GL_JournalBatch, GL_Category |
PP_ |
生產規劃 / 製造 | PP_Order, PP_Product_BOM, PP_Product_Planning |
I_ |
匯入(暫存資料表) | I_BPartner, I_Product, I_Order, I_Invoice, I_GLJournal |
T_ |
暫存(會話工作資料表) | T_Report, T_Aging, T_TrialBalance |
PA_ |
績效分析 | PA_Goal, PA_Measure, PA_Report |
R_ |
請求 / 服務管理 | R_Request, R_RequestType, R_Category |
S_ |
服務 / 資源 | S_Resource, S_ResourceType, S_TimeExpense |
W_ |
網路商店 | W_Store, W_Click, W_Basket |
HR_ |
人力資源 / 薪資 | HR_Employee, HR_Concept, HR_Process |
A_ |
資產管理 | A_Asset, A_Asset_Group, A_Depreciation |
當您遇到不熟悉的資料表時,前綴能立即縮小其功能範圍。以 M_ 開頭的資料表與物料管理相關,以 C_ 開頭的與核心業務流程相關,以此類推。
明細資料表
如前一課所述,許多表頭資料表都有對應的明細資料表。命名慣例很直觀:在表頭資料表名稱後附加 Line。C_Order 對應 C_OrderLine,C_Invoice 對應 C_InvoiceLine,GL_Journal 對應 GL_JournalLine。
自訂資料表前綴
建立自訂資料表時,您應該使用自己的前綴,以避免與核心資料表及其他自訂項目產生衝突。常見的做法包括使用兩個字母的公司縮寫(例如 XX_)或專案特定的前綴。此前綴應與您在應用程式字典中註冊的自訂實體類型一致。
標準欄位模式
iDempiere 資料模型最一致的特點之一,就是幾乎出現在每個資料表上的一組標準欄位。這些欄位實現了核心系統功能,如多租戶、稽核和軟刪除。
必要標準欄位
| 欄位 | 類型 | 用途 |
|---|---|---|
AD_Client_ID |
數值 (FK) | 識別哪個用戶端(租戶)擁有此記錄 |
AD_Org_ID |
數值 (FK) | 識別用戶端中的哪個組織擁有此記錄 |
IsActive |
Char(1) | 軟刪除標記:Y = 啟用,N = 停用(非物理刪除) |
Created |
Timestamp | 記錄首次建立的時間 |
CreatedBy |
數值 (FK 指向 AD_User) | 建立記錄的使用者 |
Updated |
Timestamp | 記錄最後修改的時間 |
UpdatedBy |
數值 (FK 指向 AD_User) | 最後修改記錄的使用者 |
這七個欄位存在於 iDempiere 的每個常規資料表中。系統的持久層(PO — Persistent Object — 框架)會自動管理 Created、CreatedBy、Updated 和 UpdatedBy,因此開發人員和使用者無需手動填寫它們。
主鍵慣例
每個資料表的主鍵欄位遵循嚴格的命名慣例:TableName_ID。資料表 C_Order 的主鍵為 C_Order_ID,資料表 M_Product 的主鍵為 M_Product_ID,資料表 AD_User 的主鍵為 AD_User_ID。這個慣例不僅僅是建議;應用程式字典和 Java 模型層依賴它來進行自動外鍵解析、連結欄位偵測和參照查詢。
主鍵值從資料庫序列生成。每個資料表都有自己的序列(例如 C_Order_Seq),系統在建立新記錄時會取得下一個值。
UUID 欄位
除了數值主鍵外,iDempiere 資料表還包含 UUID(通用唯一識別碼)欄位,遵循 TableName_UU 的模式。例如,C_Order_UU 儲存類似 a1b2c3d4-e5f6-7890-abcd-ef1234567890 的 UUID。UUID 有幾個重要用途:
- 跨系統識別:與依賴序列且在不同系統間可能不同的數值 ID 不同,UUID 是全域唯一的。這使它們對於資料遷移、同步和 2Pack 封裝來說至關重要。
- REST API 參照:透過 Web 服務公開資料時,UUID 提供穩定的、與系統無關的識別碼。
- 複製:多站點環境使用 UUID 來匹配跨伺服器的記錄。
外鍵慣例
iDempiere 中的外鍵遵循與主鍵相同的命名模式。如果資料表有一個名為 C_BPartner_ID 的欄位,它就是對 C_BPartner 資料表的外鍵參照。這種一致性意味著您可以透過移除 _ID 後綴來確定任何外鍵欄位所參照的資料表。應用程式字典的 Table Direct 參照類型利用此慣例自動解析查詢,無需額外設定。
關鍵實體
iDempiere 的資料模型包含數百個資料表,但一組核心實體構成了整個系統的骨幹。理解這些關鍵實體對於掌握商業資料如何在 iDempiere 中流動至關重要。
AD_Client:租戶
在最高層級,AD_Client 代表 iDempiere 多租戶架構中的一個租戶。每個用戶端是一個完全隔離的商業實體,擁有自己的會計科目表、業務夥伴、產品和交易。單一 iDempiere 安裝可以託管多個用戶端,每個用戶端都無法感知其他用戶端的資料。
每個 iDempiere 安裝至少有兩個用戶端:
- 系統 (AD_Client_ID = 0):包含系統層級設定、字典定義和共享參照資料。一般使用者不會直接在系統用戶端中工作。
- 您的公司用戶端(例如 AD_Client_ID = 11):包含您實際的業務資料。這是使用者登入並執行日常操作的地方。
AD_Org:組織
在用戶端內,AD_Org 代表一個組織單位。組織可以模擬部門、事業部、分公司、法人實體或您業務所需的任何其他結構單位。組織階層實現了:
- 資料隔離:記錄可以指派給特定組織,限制可見性。
- 角色存取控制:使用者可以被授予存取特定組織的權限,確保他們只看到相關資料。
- 財務報表:組織可以有自己的會計架構,用於合併或分段報表。
每個用戶端都有一個特殊的組織,其 AD_Org_ID = 0(通常標示為星號 *)。指派到組織 0 的記錄被視為在用戶端內所有組織之間共享。付款條件、幣別和稅率等參照資料通常指派到組織 0。
C_BPartner:業務夥伴
C_BPartner 資料表是 iDempiere 中最核心的實體之一。它代表您的組織與之進行業務往來的任何外部方:客戶、供應商、員工或其任意組合。單一業務夥伴記錄可以同時是客戶、供應商和員工。業務夥伴將在下一課中深入介紹。
M_Product:產品
M_Product 代表可以購買、銷售、製造或存儲的項目、服務、資源或費用。產品按產品類型(項目、服務、資源、費用)分類,項目還可以按產品類別進一步分類以用於報表和會計。主要相關資料表包括:
M_Product_Category:用於會計預設值和報表的分組。M_Product_PO:採購資訊(供應商、供應商產品編號、標價)。M_ProductPrice:特定價目表上的價格。M_Storage/M_StorageOnHand:按倉庫儲位的庫存數量。
C_Order:銷售訂單和採購訂單
C_Order 是用於銷售訂單和採購訂單的通用訂單資料表。IsSOTrx 標記區分兩者:Y 表示銷售,N 表示採購。這種統一設計意味著相同的基礎架構處理交易的兩端,應用程式字典的顯示邏輯和視窗設定會相應地調整使用者介面。
C_Invoice:發票
C_Invoice 管理客戶發票(應收帳款)和供應商發票(應付帳款),同樣使用 IsSOTrx 來區分方向。發票連結到訂單、出貨和付款,形成完整的文件鏈。
M_InOut:出貨和進貨
M_InOut 處理貨物的實體移動,涵蓋對客戶的出貨和從供應商的進貨。IsSOTrx 標記指示方向。每個 M_InOutLine 參照產品、數量和倉庫儲位。
C_Payment:付款
C_Payment 記錄從客戶收到的款項和支付給供應商的款項。付款透過分配機制(C_AllocationHdr / C_AllocationLine)連結到發票,支援部分付款、超額付款和跨發票分配。
資料隔離模型
iDempiere 的多租戶資料隔離是其最重要的架構特性之一。對於管理員和開發人員來說,理解這個模型至關重要。
三個層級的資料範圍
iDempiere 中的資料存在於三個可見性層級:
| 層級 | AD_Client_ID | AD_Org_ID | 可見性 |
|---|---|---|---|
| 系統 | 0 | 0 | 跨所有用戶端共享(字典、參照資料) |
| 用戶端範圍 | 您的用戶端 | 0 | 在用戶端內所有組織之間共享 |
| 組織特定 | 您的用戶端 | 特定組織 | 僅對有該組織存取權限的使用者可見 |
資料隔離如何運作
當使用者登入時,他們選擇一個用戶端、一個角色和一個組織。系統執行的每個資料庫查詢都會自動包含對 AD_Client_ID 的過濾,大多數查詢還會根據使用者的角色權限過濾 AD_Org_ID。這種過濾發生在框架層級,深藏在持久化和查詢基礎架構中,因此對上層的應用程式程式碼是透明的。
實際效果是:
- 登入到用戶端 A 的使用者永遠無法看到屬於用戶端 B 的資料,無論是 SQL 查詢還是 API 呼叫。
- 被限制在「東區事業部」的使用者無法看到屬於「西區事業部」的記錄。
- 系統層級記錄(用戶端 0,組織 0)對所有用戶端可見,作為唯讀參照資料。
- 用戶端範圍記錄(用戶端內的組織 0)對該用戶端內的所有組織可見。
來自系統用戶端的共享資料
系統用戶端 (AD_Client_ID = 0) 保存所有租戶共用的資料,包括:
- 應用程式字典定義(AD_Table、AD_Column、AD_Window 等)
- 系統層級參照資料(國家、幣別、語言)
- 預設會計科目表範本
使用初始用戶端設定流程建立新用戶端時,系統會從系統用戶端複製相關參照資料,並在需要時建立用戶端特定的版本。
組織階層
iDempiere 中的組織可以使用 AD_Tree 機制建立階層結構。一個典型的多分支公司可能如下:
公司(用戶端)
├── 總部(組織)
│ ├── 財務部門(組織)
│ └── 人力資源部門(組織)
├── 東區(組織)
│ ├── 紐約辦公室(組織)
│ └── 波士頓辦公室(組織)
└── 西區(組織)
├── 洛杉磯辦公室(組織)
└── 舊金山辦公室(組織)
有權存取父組織的使用者通常可以看到所有子組織的資料,這取決於角色的 IsAccessAllOrgs 設定和組織存取設定。此階層結構既實現了細粒度的資料隔離,又支援合併報表。
理解記錄 ID
iDempiere 中的每條記錄都由其數值 ID(TableName_ID 欄位)識別。這些 ID 對於理解資料關聯至關重要。當您在訂單記錄中看到 C_BPartner_ID = 119 時,您就知道它參照了 C_BPartner 資料表中的業務夥伴記錄 119。
記錄 ID 的重要特性:
- 序列生成:ID 從資料庫序列自動指派,不可由使用者設定。
- 系統特定:同一個業務夥伴在一台伺服器上可能是
C_BPartner_ID = 119,在另一台上可能是C_BPartner_ID = 5023。切勿在自訂程式中硬編碼 ID。 - 保留範圍:低於特定閾值(通常為 1,000,000)的 ID 保留給標準種子資料。自訂記錄使用超過此閾值的 ID。
- 零表示未設定:ID 值為 0 通常表示「未指定」,並可能有特殊行為(例如 AD_Org_ID = 0 表示共享)。
最佳實務:撰寫 SQL 查詢或自訂程式時,應始終透過 UUID 或唯一鍵值欄位(如 Value)來參照記錄,而非使用數值 ID。這確保您的程式碼在不同環境中都能正確運作。
綜合應用:文件流程
要了解這些實體如何協同運作,請考慮一個簡單的銷售週期:
- 建立一個業務夥伴(
C_BPartner)作為客戶。 - 為該客戶建立一筆銷售訂單(
C_Order,IsSOTrx='Y'),其中明細行參照產品(M_Product)。 - 訂單完成後,生成一筆出貨單(
M_InOut),扣減庫存。 - 從訂單或出貨單生成一張發票(
C_Invoice)。 - 收到一筆付款(
C_Payment),並將其分配到發票。
這些文件中的每一個都帶有 AD_Client_ID 和 AD_Org_ID,將它們連結到所屬的租戶和組織上下文。外鍵(如 C_Order 上的 C_BPartner_ID、C_OrderLine 上的 C_Order_ID)將這些實體編織成一條可追溯的鏈條,支援報表、稽核和商業智慧。
重點摘要
- 資料表前綴(AD_、C_、M_、GL_、PP_、I_、T_)能立即識別資料表所屬的功能模組。
- 七個必要標準欄位(AD_Client_ID、AD_Org_ID、IsActive、Created、CreatedBy、Updated、UpdatedBy)出現在每個資料表上,實現多租戶、軟刪除和稽核追蹤。
- 主鍵遵循 TableName_ID 慣例,外鍵使用與被參照資料表主鍵相同的名稱。
- UUID 欄位(TableName_UU)為遷移、複製和 Web 服務提供與系統無關的記錄識別。
- AD_Client 提供租戶隔離;AD_Org 提供租戶內的組織資料隔離。
- 資料存在於三個範圍:系統(全域共享)、用戶端範圍(租戶內共享)和組織特定(限定於某個組織)。
- 關鍵實體(C_BPartner、M_Product、C_Order、C_Invoice、M_InOut、C_Payment)構成驅動所有業務流程的文件鏈。
下一步
在下一課業務夥伴管理中,您將深入探討 C_BPartner 實體,了解客戶、供應商和員工的設定方式、地址和聯絡人的管理方式,以及業務夥伴如何連結到交易文件鏈。
日本語
概要
- 学習内容:すべての iDempiere システムの基盤を構成するコアデータベーステーブル、命名規則、標準カラムパターン、主要エンティティ、およびクライアント・組織のデータ分離モデル。
- 前提条件:レッスン 6 – ウィンドウとタブの操作
- 想定読了時間:22 分
はじめに
すべてのエンタープライズリソースプランニングシステムの核心は、構造化されたデータベーステーブルの集合とそれらの間のリレーションシップです。iDempiere のデータモデルは 20 年以上にわたり洗練されてきました。Compiere から ADempiere を経て、現在の形へと進化しています。基本的なデータ入力を超えてシステムの仕組みを真に理解したい方にとって、このデータモデルの理解は不可欠です。
このレッスンでは、iDempiere の数百のテーブルをすぐに識別できるようにする命名規則、すべてのテーブルに表示される標準カラム、基本的なビジネス概念を表す主要エンティティ、そしてマルチテナント運用を可能にするデータ分離モデルについて学びます。この知識は、ビジネスパートナー管理から財務転記、カスタム開発に至るまで、以降のすべての内容の基盤となります。
テーブル命名規則
iDempiere はプレフィックス規則を使用してテーブルを論理的なグループに整理しています。テーブル名のプレフィックスは、それがどの機能領域に属するかを即座に示します。これらのプレフィックスを知ることで、テーブルをすばやく見つけ、一目でその目的を理解できます。
コアテーブルプレフィックス
| プレフィックス | モジュール | 例 |
|---|---|---|
AD_ |
アプリケーション辞書 / システム管理 | AD_Table, AD_Column, AD_Window, AD_User, AD_Role, AD_Client, AD_Org |
C_ |
コアビジネス(パートナー、受注、請求書、支払、会計) | C_BPartner, C_Order, C_Invoice, C_Payment, C_AcctSchema, C_Currency |
M_ |
資材管理(製品、倉庫、在庫) | M_Product, M_Warehouse, M_InOut, M_Inventory, M_Locator, M_PriceList |
GL_ |
総勘定元帳 | GL_Journal, GL_JournalLine, GL_JournalBatch, GL_Category |
PP_ |
生産計画 / 製造 | PP_Order, PP_Product_BOM, PP_Product_Planning |
I_ |
インポート(一時ステージングテーブル) | I_BPartner, I_Product, I_Order, I_Invoice, I_GLJournal |
T_ |
一時テーブル(セッションベースの作業テーブル) | T_Report, T_Aging, T_TrialBalance |
PA_ |
パフォーマンス分析 | PA_Goal, PA_Measure, PA_Report |
R_ |
リクエスト / サービス管理 | R_Request, R_RequestType, R_Category |
S_ |
サービス / リソース | S_Resource, S_ResourceType, S_TimeExpense |
W_ |
Web ストア | W_Store, W_Click, W_Basket |
HR_ |
人事 / 給与 | HR_Employee, HR_Concept, HR_Process |
A_ |
資産管理 | A_Asset, A_Asset_Group, A_Depreciation |
見慣れないテーブルに遭遇した場合、プレフィックスによってその機能領域を即座に絞り込めます。M_ で始まるテーブルは資材管理に関連し、C_ で始まるテーブルはコアビジネスプロセスに関連する、というようになります。
明細テーブル
前のレッスンで説明したように、多くのヘッダーテーブルには対応する明細テーブルがあります。命名規則はシンプルで、ヘッダーテーブル名に Line を付加します。C_Order には C_OrderLine、C_Invoice には C_InvoiceLine、GL_Journal には GL_JournalLine があります。
カスタムテーブルプレフィックス
カスタムテーブルを作成する際は、コアテーブルや他のカスタマイズとの競合を避けるため、独自のプレフィックスを使用する必要があります。一般的なアプローチとしては、2 文字の会社略称(例:XX_)やプロジェクト固有のプレフィックスの使用があります。このプレフィックスは、アプリケーション辞書に登録したカスタムエンティティタイプと整合させる必要があります。
標準カラムパターン
iDempiere のデータモデルで最も一貫している側面の一つは、ほぼすべてのテーブルに表示される標準カラムのセットです。これらのカラムは、マルチテナンシー、監査、論理削除などのコアシステム機能を実現します。
必須標準カラム
| カラム | 型 | 目的 |
|---|---|---|
AD_Client_ID |
数値 (FK) | このレコードを所有するクライアント(テナント)を識別 |
AD_Org_ID |
数値 (FK) | クライアント内のどの組織がこのレコードを所有するかを識別 |
IsActive |
Char(1) | 論理削除フラグ:Y = アクティブ、N = 無効化(物理削除ではない) |
Created |
Timestamp | レコードが最初に作成された日時 |
CreatedBy |
数値 (FK:AD_User) | レコードを作成したユーザー |
Updated |
Timestamp | レコードが最後に変更された日時 |
UpdatedBy |
数値 (FK:AD_User) | レコードを最後に変更したユーザー |
これら 7 つのカラムは iDempiere のすべての通常のデータテーブルに存在します。システムの永続化レイヤー(PO — Persistent Object — フレームワーク)が Created、CreatedBy、Updated、UpdatedBy を自動的に管理するため、開発者やユーザーが手動で入力する必要はありません。
主キー規則
各テーブルの主キーカラムは厳格な命名規則に従います:TableName_ID。テーブル C_Order の主キーは C_Order_ID、テーブル M_Product は M_Product_ID、テーブル AD_User は AD_User_ID です。この規則は単なる推奨ではなく、アプリケーション辞書と Java モデルレイヤーが自動外部キー解決、リンクカラム検出、参照ルックアップのために依存しています。
主キー値はデータベースシーケンスから生成されます。各テーブルには独自のシーケンス(例:C_Order_Seq)があり、新しいレコードを作成する際にシステムが次の値を取得します。
UUID カラム
数値主キーに加えて、iDempiere のテーブルには TableName_UU のパターンに従う UUID(汎用一意識別子)カラムが含まれています。例えば、C_Order_UU には a1b2c3d4-e5f6-7890-abcd-ef1234567890 のような UUID が格納されます。UUID にはいくつかの重要な目的があります:
- システム間識別:シーケンスに依存しシステム間で異なる可能性のある数値 ID とは異なり、UUID はグローバルに一意です。これにより、データ移行、同期、2Pack パッケージングに不可欠なものとなっています。
- REST API 参照:Web サービスを通じてデータを公開する際、UUID は安定したシステム非依存の識別子を提供します。
- レプリケーション:マルチサイト環境では UUID を使用してサーバー間のレコードを照合します。
外部キー規則
iDempiere の外部キーは主キーと同じ命名パターンに従います。テーブルに C_BPartner_ID という名前のカラムがあれば、それは C_BPartner テーブルへの外部キー参照です。この一貫性により、_ID サフィックスを除去するだけで、任意の外部キーカラム名から参照先テーブルを特定できます。アプリケーション辞書の Table Direct 参照タイプはこの規則を利用して、追加設定なしでルックアップを自動的に解決します。
主要エンティティ
iDempiere のデータモデルには数百のテーブルが含まれていますが、一連のコアエンティティがシステム全体のバックボーンを形成しています。これらの主要エンティティを理解することは、ビジネスデータが iDempiere をどのように流れるかを把握するために不可欠です。
AD_Client:テナント
最上位レベルでは、AD_Client は iDempiere のマルチテナントアーキテクチャにおけるテナントを表します。各クライアントは独自の勘定科目表、ビジネスパートナー、製品、取引を持つ完全に分離されたビジネスエンティティです。単一の iDempiere インストールで複数のクライアントをホストでき、各クライアントは他のクライアントのデータを認識できません。
すべての iDempiere インストールには少なくとも 2 つのクライアントがあります:
- System (AD_Client_ID = 0):システムレベルの設定、辞書定義、および共有参照データが含まれます。一般ユーザーは System クライアントで直接作業することはありません。
- 自社クライアント(例:AD_Client_ID = 11):実際のビジネスデータが含まれます。ユーザーがログインして日常業務を行う場所です。
AD_Org:組織
クライアント内では、AD_Org は組織単位を表します。組織は部門、事業部、支店、法人、またはビジネスに必要なその他の構造単位をモデル化できます。組織階層は以下を可能にします:
- データ分離:レコードを特定の組織に割り当て、可視性を制限できます。
- ロールベースアクセス:ユーザーに特定の組織へのアクセスを付与し、関連するデータのみが表示されるようにできます。
- 財務レポート:組織は連結または部門別レポートのために独自の会計スキーマを持つことができます。
すべてのクライアントには AD_Org_ID = 0(通常アスタリスク * と表示)の特別な組織があります。組織 0 に割り当てられたレコードは、クライアント内のすべての組織間で共有されるものと見なされます。支払条件、通貨、税率などの参照データは通常、組織 0 に割り当てられます。
C_BPartner:ビジネスパートナー
C_BPartner テーブルは iDempiere で最も中心的なエンティティの一つです。組織が取引を行うあらゆる外部当事者(顧客、仕入先、従業員、またはそれらの組み合わせ)を表します。単一のビジネスパートナーレコードは、顧客、仕入先、従業員を同時に兼ねることができます。ビジネスパートナーについては次のレッスンで詳しく説明します。
M_Product:製品
M_Product は、購入、販売、製造、または在庫管理が可能なアイテム、サービス、リソース、または経費を表します。製品は製品タイプ(アイテム、サービス、リソース、経費)で分類され、アイテムはレポートと会計のために製品カテゴリでさらに分類できます。主要な関連テーブルは以下の通りです:
M_Product_Category:会計デフォルトとレポートのためのグループ化。M_Product_PO:購買情報(仕入先、仕入先製品番号、定価)。M_ProductPrice:特定の価格リスト上の価格。M_Storage/M_StorageOnHand:倉庫ロケーター別の在庫数量。
C_Order:受注と発注
C_Order は受注と発注の両方に使用される汎用の注文テーブルです。IsSOTrx フラグで両者を区別します:Y は受注、N は発注です。この統一設計により、同じインフラストラクチャが取引の両方を処理し、アプリケーション辞書の表示ロジックとウィンドウ設定がそれに応じてユーザーインターフェースを適応させます。
C_Invoice:請求書
C_Invoice は顧客請求書(売掛金)と仕入先請求書(買掛金)の両方を管理し、同様に IsSOTrx で方向を区別します。請求書は注文、出荷、支払にリンクし、完全なドキュメントチェーンを形成します。
M_InOut:出荷と入荷
M_InOut は商品の物理的な移動を処理し、顧客への出荷と仕入先からの入荷の両方をカバーします。IsSOTrx フラグが方向を示します。各 M_InOutLine は製品、数量、倉庫ロケーターを参照します。
C_Payment:支払
C_Payment は顧客からの入金と仕入先への支払を記録します。支払は配賦メカニズム(C_AllocationHdr / C_AllocationLine)を通じて請求書にリンクされ、部分支払、過払い、およびクロス請求書配賦をサポートします。
データ分離モデル
iDempiere のマルチテナントデータ分離は、最も重要なアーキテクチャ機能の一つです。管理者と開発者の両方にとって、このモデルの理解は不可欠です。
3 つのデータスコープレベル
iDempiere のデータは 3 つの可視性レベルで存在します:
| レベル | AD_Client_ID | AD_Org_ID | 可視性 |
|---|---|---|---|
| システム | 0 | 0 | すべてのクライアント間で共有(辞書、参照データ) |
| クライアント全体 | 自社クライアント | 0 | クライアント内のすべての組織間で共有 |
| 組織固有 | 自社クライアント | 特定の組織 | その組織へのアクセス権を持つユーザーのみに表示 |
データ分離の仕組み
ユーザーがログインする際、クライアント、ロール、組織を選択します。システムが実行するすべてのデータベースクエリには AD_Client_ID に対するフィルタが自動的に含まれ、ほとんどのクエリではユーザーのロール権限に基づいて AD_Org_ID によるフィルタも適用されます。このフィルタリングはフレームワークレベルで、永続化レイヤーとクエリインフラストラクチャの深い部分で行われるため、上位のアプリケーションコードからは透過的です。
実際の効果は以下の通りです:
- クライアント A にログインしたユーザーは、SQL クエリや API 呼び出しに関係なく、クライアント B に属するデータを見ることはできません。
- 「東部事業部」に制限されたユーザーは「西部事業部」に属するレコードを見ることはできません。
- システムレベルのレコード(クライアント 0、組織 0)はすべてのクライアントに読み取り専用の参照データとして表示されます。
- クライアント全体のレコード(クライアント内の組織 0)はそのクライアント内のすべての組織に表示されます。
System クライアントからの共有データ
System クライアント (AD_Client_ID = 0) には、すべてのテナントに共通のデータが保持されています。これには以下が含まれます:
- アプリケーション辞書の定義(AD_Table、AD_Column、AD_Window など)
- システムレベルの参照データ(国、通貨、言語)
- デフォルトの勘定科目表テンプレート
初期クライアントセットアッププロセスを使用して新しいクライアントを作成すると、System クライアントから関連する参照データがコピーされ、必要に応じてクライアント固有のバージョンが作成されます。
組織階層
iDempiere の組織は AD_Tree メカニズムを使用して階層構造にできます。典型的な複数拠点の会社は以下のようになります:
会社(クライアント)
├── 本社(組織)
│ ├── 財務部門(組織)
│ └── 人事部門(組織)
├── 東部地域(組織)
│ ├── ニューヨークオフィス(組織)
│ └── ボストンオフィス(組織)
└── 西部地域(組織)
├── ロサンゼルスオフィス(組織)
└── サンフランシスコオフィス(組織)
親組織へのアクセス権を持つユーザーは、ロールの IsAccessAllOrgs 設定と組織アクセス設定に応じて、通常すべての子組織のデータを見ることができます。この階層により、きめ細かなデータ分離と連結レポートの両方が可能になります。
レコード ID の理解
iDempiere のすべてのレコードは、その数値 ID(TableName_ID カラム)で識別されます。これらの ID はデータの関連性を理解するために不可欠です。注文レコードで C_BPartner_ID = 119 と表示されていれば、C_BPartner テーブルのビジネスパートナーレコード 119 を参照していることがわかります。
レコード ID の重要な特性:
- シーケンス生成:ID はデータベースシーケンスから自動的に割り当てられます。ユーザーによる設定はできません。
- システム固有:同じビジネスパートナーが、あるサーバーでは
C_BPartner_ID = 119、別のサーバーではC_BPartner_ID = 5023となることがあります。カスタマイズで ID をハードコードしないでください。 - 予約範囲:特定の閾値(通常 1,000,000)未満の ID は標準シードデータ用に予約されています。カスタムレコードはこの閾値を超える ID を使用します。
- ゼロは未設定を意味する:ID 値 0 は通常「未指定」を意味し、特別な動作をする場合があります(例:AD_Org_ID = 0 は共有を意味する)。
ベストプラクティス:SQL クエリやカスタマイズを記述する際は、数値 ID ではなく UUID または一意のキーフィールド(Value など)でレコードを参照してください。これにより、異なる環境間でコードが正しく動作することが保証されます。
すべてを統合する:ドキュメントフロー
これらのエンティティがどのように連携するかを理解するために、シンプルな販売サイクルを考えてみましょう:
- ビジネスパートナー(
C_BPartner)を顧客として作成します。 - その顧客に対して、製品(
M_Product)を参照する明細行を含む受注(C_Order、IsSOTrx='Y')を作成します。 - 注文が完了すると、在庫を減少させる出荷(
M_InOut)が生成されます。 - 注文または出荷から請求書(
C_Invoice)が生成されます。 - 支払(
C_Payment)を受領し、請求書に配賦します。
これらの各ドキュメントは AD_Client_ID と AD_Org_ID を持ち、テナントと組織のコンテキストにリンクされています。外部キー(C_Order 上の C_BPartner_ID、C_OrderLine 上の C_Order_ID など)がこれらのエンティティを追跡可能なチェーンに織り込み、レポート、監査、ビジネスインテリジェンスをサポートします。
重要ポイント
- テーブルプレフィックス(AD_、C_、M_、GL_、PP_、I_、T_)は、テーブルが属する機能モジュールを即座に識別します。
- 7 つの必須標準カラム(AD_Client_ID、AD_Org_ID、IsActive、Created、CreatedBy、Updated、UpdatedBy)はすべてのテーブルに存在し、マルチテナンシー、論理削除、監査追跡を実現します。
- 主キーは TableName_ID 規則に従い、外部キーは参照先テーブルの主キーと同じ名前を使用します。
- UUID カラム(TableName_UU)は、移行、レプリケーション、Web サービスのためのシステム非依存のレコード識別を提供します。
- AD_Client はテナント分離を提供し、AD_Org はテナント内の組織データ分離を提供します。
- データは 3 つのスコープで存在します:システム(グローバル共有)、クライアント全体(テナント内共有)、組織固有(特定の組織に制限)。
- 主要エンティティ(C_BPartner、M_Product、C_Order、C_Invoice、M_InOut、C_Payment)はすべてのビジネスプロセスを駆動するドキュメントチェーンを形成します。
次のステップ
次のレッスンビジネスパートナー管理では、C_BPartner エンティティを深く掘り下げ、顧客・仕入先・従業員の設定方法、住所と連絡先の管理方法、そしてビジネスパートナーが取引ドキュメントチェーンにどのように接続されるかを学びます。