objectbox-go icon indicating copy to clipboard operation
objectbox-go copied to clipboard

go generate fails due to missing entity

Open jpeeler opened this issue 5 years ago • 6 comments

Reproducer here: https://github.com/jpeeler/objectbox-test

I don't understand the failure as Credential is present in the same file as Institution, which is clearly found.

Copied output from commit:

$ go generate
Generating ObjectBox bindings for main.go
2020/04/04 21:58:49 Notice: skipping unavailable (private) property wall found in MyInstitution.Institution.InstitutionStatus.ItemLogins.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property ext found in MyInstitution.Institution.InstitutionStatus.ItemLogins.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property loc found in MyInstitution.Institution.InstitutionStatus.ItemLogins.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property wall found in MyInstitution.Institution.InstitutionStatus.TransactionsUpdates.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property ext found in MyInstitution.Institution.InstitutionStatus.TransactionsUpdates.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property loc found in MyInstitution.Institution.InstitutionStatus.TransactionsUpdates.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property wall found in MyInstitution.Institution.InstitutionStatus.Auth.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property ext found in MyInstitution.Institution.InstitutionStatus.Auth.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property loc found in MyInstitution.Institution.InstitutionStatus.Auth.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property wall found in MyInstitution.Institution.InstitutionStatus.Balance.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property ext found in MyInstitution.Institution.InstitutionStatus.Balance.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property loc found in MyInstitution.Institution.InstitutionStatus.Balance.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property wall found in MyInstitution.Institution.InstitutionStatus.Identity.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property ext found in MyInstitution.Institution.InstitutionStatus.Identity.LastStatusChange
2020/04/04 21:58:49 Notice: skipping unavailable (private) property loc found in MyInstitution.Institution.InstitutionStatus.Identity.LastStatusChange
can't merge binding model information: entity named 'Credential' was not found
exit status 2
main.go:8: running "go": exit status 1```

jpeeler avatar Apr 05 '20 02:04 jpeeler

So you're trying to save data from some 3rd party library. As expected, that library doesn't have the expected model annotations, namely the problem is with Institution.Credentials field:

type Institution struct {
	Credentials  []Credential `json:"credentials"`
        ...
}

type Credential struct {
	Label string `json:"label"`
	Name  string `json:"name"`
	Type  string `json:"type"`
}

ObjectBox-Go thinks Institution.Credentials field is a many-to-many when creating the model for Institution but can't find the target entity Credential because it's not recognized as such (and cannot be, since it doesn't have a mandatory Id/ID field)

vaind avatar Apr 06 '20 09:04 vaind

Could you explain what you're trying to achieve? What data do you want to store? How do you intend to read/query the data? We have done some custom handling of a pre-defined model here for EdgeX https://github.com/objectbox/edgex-objectbox/tree/fuji/internal/pkg/db/objectbox but that may be an overkill for your use-case

vaind avatar Apr 06 '20 10:04 vaind

I had planned on storing MyInstitutions. I thought at a minimum I would be able to do a GetAll() to get the data (each institution) back. Ideally, the embedded part would be queryable. I was really only expecting that the embedding "trick" would work just for fields in Institution that are primitive DB types, nothing else.

jpeeler avatar Apr 06 '20 23:04 jpeeler

Unfortunately, that's not gonna work without some custom handling similar to the EdgeX example I've linked above. We've opted for a better-safe-than-sorry approach in ObjectBox-Go of not skipping unknown fields but failing the generation altogether, with user being able to either fix the time or skip them explicitly by tagging with objectbox:"-".

vaind avatar Apr 14 '20 11:04 vaind

Understood - if you want to close this issue since it's a "can't/won't fix", that's fine.

jpeeler avatar Apr 14 '20 23:04 jpeeler

Hey @vaind , I am a somewhat newcomer in golang, and was going to try ObjectBox for our project, which heavily relies on 3rd party packages and their types to be stored. Did I get it right, that for such cases, ObjectBox is not a good option, because it is not easy/straightforward to store 3rd party types in the db, because we can't annotate them properly?

IvanBelyakoff avatar Jun 11 '23 12:06 IvanBelyakoff