#996: Kost2DO.kt
projectforge-business/src/main/kotlin/org/projectforge/business/fibu/kost/Kost2DO.kt Type: JPA Entity (DO) · Purpose: Kost2 cost center entity with 8-digit number + cost type · Source: projectforge-business/src/main/kotlin/org/projectforge/business/fibu/kost/Kost2DO.kt 252 lines · 149 code · 78 comments · 25 blank
Represents a Kost2 cost center — the finer-grained cost entity (compared to Kost1). A Kost2 is identified by a combination of 3 numeric components (Nummernkreis, Bereich, Teilbereich = 6 digits) and a Kost2Art (cost type, 2 digits). Each Kost2 belongs to a project and has a specific cost type classification.
Entity Design
| Field | Type | DB Column | Description |
kostentraegerStatus | KostentraegerStatus? | VARCHAR(30) | ACTIVE, NONACTIVE, or ENDED |
nummernkreis | Int | INT | First digit (1-9) |
bereich | Int | INT | Digits 2-4; for 5.xxx this is the customer number |
teilbereich | Int | INT | Digits 5-6 |
kost2Art | Kost2ArtDO? | FK kost2_art_id | ManyToOne to cost type (2-digit classification) |
workFraction | BigDecimal? | PRECISION(10,5) | Work allocation fraction |
description | String? | VARCHAR(4000) | Description |
comment | String? | VARCHAR(4000) | Optional comment |
projekt | ProjektDO? | FK projekt_id | Associated project (lazy-loaded) |
Computed (Transient) Properties
| Property | Type | Description |
effectiveKostentraegerStatus | KostentraegerStatus? | Inherits ENDED from project if project is ENDED or deleted |
nummer | Int | Computed 8-digit integer (via KostFormatter.getKostAsInt) |
formattedNumber | String | Formatted as #.###.##.## (indexed for search) |
rawNumberString | String | 8-digit compact string for search indexing |
toolTip | String | Formatted tooltip via OldKostFormatter |
Named Queries
| Name | Purpose |
FIND_BY_NK_BEREICH_TEILBEREICH_KOST2ART | Find by all 4 components |
FIND_OTHER_BY_NK_BEREICH_TEILBEREICH_KOST2ART | Find duplicate (exclude self) for uniqueness check |
FIND_ACTIVES_BY_NK_BEREICH_TEILBEREICH | Find active entries by 6-digit prefix |
Virtual Status Inheritance
The effectiveKostentraegerStatus property implements a key design pattern (introduced in commit 8239a53ee): if the linked Projekt has status ENDED or is deleted, the Kost2 is treated as ENDED regardless of its own status. This avoids data inconsistency when projects are closed.
Persistence Details
- Mapped to
T_FIBU_KOST2 with unique constraint on all 4 numeric components
- Indexes on
kost2_art_id and projekt_id for join performance
- Extends
DefaultBaseDO, implements Comparable<Kost2DO> and DisplayNameCapable
- Implements
@JsonCreator factory for deserialization from Long ID
- Equals/hashCode uses nummernkreis, bereich, teilbereich, and kost2Art
- All Kotlin properties declared
open for Hibernate lazy-loading proxy support
Source Code (abridged)
@Entity @Indexed @Table(name = "T_FIBU_KOST2", ...)
open class Kost2DO : DefaultBaseDO(), Comparable<Kost2DO>, DisplayNameCapable {
open var kostentraegerStatus: KostentraegerStatus? = null
val effectiveKostentraegerStatus: KostentraegerStatus?
get() {
val projektRef = PfCaches.instance.getProjektIfNotInitialized(projekt) ?: projekt
if (projektRef != null &&
(projektRef.status == ProjektStatus.ENDED || projektRef.deleted))
return KostentraegerStatus.ENDED
return kostentraegerStatus
}
open var nummernkreis: Int = 0
open var bereich: Int = 0
open var teilbereich: Int = 0
open var kost2Art: Kost2ArtDO? = null
open var projekt: ProjektDO? = null
// ... formattedNumber, rawNumberString, toolTip computed properties
}
Git History
868d6abb7 2025 -> 2026
5c652782f AbstractTestBase initializes PfCaches.
dca4456f7 Fixed for test-cases.
8239a53ee Kost2: Virtuelle Status-Vererbung von ProjektDO
38e843800 CostSearch: search for plain number string.
63081666f Source file headers: 2024-> 2025.
0237d5eba Json: IdOnlySerializer and IdsOnlySerializer.
98555d5d8 Bugfix: search for numbers.
b3782c8a8 Migration stuff...
c8f8ed935 All entities FetchType.LAZY.
4c04cfd65 MAJOR-CHANGE! Integer id's to Long id's.
a1cf6f591 Code Cleanup
b78b870bd ShortDisplayNameCapable -> DisplayNameCapable
8675a1dbe Kotlin JPA entities declared open (lazy loading fix)
252b28955 JsonCreator for deserialization from Int
d849a79cc JsonCreator for deserialization from Number
0de418e75 DTO Tenant added to BaseDTO.
6d1f7a7cd Kost2DO.java -> Kost2DO.kt